Three.js 326.8 KB
Newer Older
1
// Three.js r45dev - http://github.com/mrdoob/three.js
2
var THREE=THREE||{};if(!self.Int32Array)self.Int32Array=Array,self.Float32Array=Array;THREE.Color=function(b){b!==void 0&&this.setHex(b);return this};
3 4
THREE.Color.prototype={constructor:THREE.Color,r:1,g:1,b:1,copy:function(b){this.r=b.r;this.g=b.g;this.b=b.b;return this},setRGB:function(b,c,e){this.r=b;this.g=c;this.b=e;return this},setHSV:function(b,c,e){var f,m,k;if(e==0)this.r=this.g=this.b=0;else switch(f=Math.floor(b*6),m=b*6-f,b=e*(1-c),k=e*(1-c*m),c=e*(1-c*(1-m)),f){case 1:this.r=k;this.g=e;this.b=b;break;case 2:this.r=b;this.g=e;this.b=c;break;case 3:this.r=b;this.g=k;this.b=e;break;case 4:this.r=c;this.g=b;this.b=e;break;case 5:this.r=
e;this.g=b;this.b=k;break;case 6:case 0:this.r=e,this.g=c,this.b=b}return this},setHex:function(b){b=Math.floor(b);this.r=(b>>16&255)/255;this.g=(b>>8&255)/255;this.b=(b&255)/255;return this},getHex:function(){return~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},getContextStyle:function(){return"rgb("+Math.floor(this.r*255)+","+Math.floor(this.g*255)+","+Math.floor(this.b*255)+")"},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}};
5
THREE.Vector2=function(b,c){this.x=b||0;this.y=c||0};
6 7
THREE.Vector2.prototype={constructor:THREE.Vector2,set:function(b,c){this.x=b;this.y=c;return this},copy:function(b){this.x=b.x;this.y=b.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;return this},addSelf:function(b){this.x+=b.x;this.y+=b.y;return this},sub:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;return this},subSelf:function(b){this.x-=b.x;this.y-=b.y;return this},multiplyScalar:function(b){this.x*=b;this.y*=b;return this},
divideScalar:function(b){b?(this.x/=b,this.y/=b):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(b){return Math.sqrt(this.distanceToSquared(b))},distanceToSquared:function(b){var c=this.x-b.x,b=this.y-b.y;return c*c+b*b},setLength:function(b){return this.normalize().multiplyScalar(b)},
M
Mr.doob 已提交
8
equals:function(b){return b.x==this.x&&b.y==this.y}};THREE.Vector3=function(b,c,e){this.x=b||0;this.y=c||0;this.z=e||0};
M
Mr.doob 已提交
9 10 11 12
THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(b,c,e){this.x=b;this.y=c;this.z=e;return this},setX:function(b){this.x=b;return this},setY:function(b){this.y=b;return this},setZ:function(b){this.z=b;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;return this},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},add:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;this.z=b.z+c.z;return this},addSelf:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;return this},
addScalar:function(b){this.x+=b;this.y+=b;this.z+=b;return this},sub:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;this.z=b.z-c.z;return this},subSelf:function(b){this.x-=b.x;this.y-=b.y;this.z-=b.z;return this},multiply:function(b,c){this.x=b.x*c.x;this.y=b.y*c.y;this.z=b.z*c.z;return this},multiplySelf:function(b){this.x*=b.x;this.y*=b.y;this.z*=b.z;return this},multiplyScalar:function(b){this.x*=b;this.y*=b;this.z*=b;return this},divideSelf:function(b){this.x/=b.x;this.y/=b.y;this.z/=b.z;return this},
divideScalar:function(b){b?(this.x/=b,this.y/=b,this.z/=b):this.set(0,0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return this.x+this.y+this.z},normalize:function(){return this.divideScalar(this.length())},setLength:function(b){return this.normalize().multiplyScalar(b)},
cross:function(b,c){this.x=b.y*c.z-b.z*c.y;this.y=b.z*c.x-b.x*c.z;this.z=b.x*c.y-b.y*c.x;return this},crossSelf:function(b){return this.set(this.y*b.z-this.z*b.y,this.z*b.x-this.x*b.z,this.x*b.y-this.y*b.x)},distanceTo:function(b){return Math.sqrt(this.distanceToSquared(b))},distanceToSquared:function(b){return(new THREE.Vector3).sub(this,b).lengthSq()},setPositionFromMatrix:function(b){this.x=b.n14;this.y=b.n24;this.z=b.n34},setRotationFromMatrix:function(b){var c=Math.cos(this.y);this.y=Math.asin(b.n13);
13 14 15
Math.abs(c)>1.0E-5?(this.x=Math.atan2(-b.n23/c,b.n33/c),this.z=Math.atan2(-b.n12/c,b.n11/c)):(this.x=0,this.z=Math.atan2(b.n21,b.n22))},isZero:function(){return this.lengthSq()<1.0E-4}};THREE.Vector4=function(b,c,e,f){this.x=b||0;this.y=c||0;this.z=e||0;this.w=f!==void 0?f:1};
THREE.Vector4.prototype={constructor:THREE.Vector4,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!==void 0?b.w:1},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;this.z=b.z+c.z;this.w=b.w+c.w;return this},addSelf:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;this.w+=b.w;return this},sub:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;this.z=b.z-
c.z;this.w=b.w-c.w;return this},subSelf:function(b){this.x-=b.x;this.y-=b.y;this.z-=b.z;this.w-=b.w;return this},multiplyScalar:function(b){this.x*=b;this.y*=b;this.z*=b;this.w*=b;return this},divideScalar:function(b){b?(this.x/=b,this.y/=b,this.z/=b,this.w/=b):(this.z=this.y=this.x=0,this.w=1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z+this.w*b.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},
16
normalize:function(){return this.divideScalar(this.length())},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};
17
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;c<e;c++)Array.prototype.push.apply(f,this.intersectObject(b[c]));f.sort(function(b,e){return b.distance-e.distance});return f},intersectObject:function(b){function c(b,e,c){var f;f=c.clone().subSelf(b).dot(e);if(f<=0)return null;b=b.clone().addSelf(e.clone().multiplyScalar(f));return c.distanceTo(b)}function e(b,e,c,f){var f=f.clone().subSelf(e),
18 19 20 21 22 23
c=c.clone().subSelf(e),m=b.clone().subSelf(e),b=f.dot(f),e=f.dot(c),f=f.dot(m),k=c.dot(c),c=c.dot(m),m=1/(b*k-e*e),k=(k*f-e*c)*m,b=(b*c-e*f)*m;return k>0&&b>0&&k+b<1}if(b instanceof THREE.Particle){var f=c(this.origin,this.direction,b.matrixWorld.getPosition());if(f==null||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.matrixWorld.getPosition());if(f==null||f>b.geometry.boundingSphere.radius*Math.max(b.scale.x,
Math.max(b.scale.y,b.scale.z)))return[];var m,k,h,n,o,u,v,t,x,w,y=b.geometry,A=y.vertices,z=[],f=0;for(m=y.faces.length;f<m;f++)if(k=y.faces[f],x=this.origin.clone(),w=this.direction.clone(),u=b.matrixWorld,h=u.multiplyVector3(k.centroid.clone()).subSelf(x),t=h.dot(w),!(t<=0)&&(h=u.multiplyVector3(A[k.a].position.clone()),n=u.multiplyVector3(A[k.b].position.clone()),o=u.multiplyVector3(A[k.c].position.clone()),u=k instanceof THREE.Face4?u.multiplyVector3(A[k.d].position.clone()):null,v=b.matrixRotationWorld.multiplyVector3(k.normal.clone()),
t=w.dot(v),b.doubleSided||(b.flipSided?t>0:t<0)))if(t=v.dot((new THREE.Vector3).sub(h,x))/t,x=x.addSelf(w.multiplyScalar(t)),k instanceof THREE.Face3)e(x,h,n,o)&&(k={distance:this.origin.distanceTo(x),point:x,face:k,object:b},z.push(k));else if(k instanceof THREE.Face4&&(e(x,h,n,u)||e(x,n,o,u)))k={distance:this.origin.distanceTo(x),point:x,face:k,object:b},z.push(k);z.sort(function(b,e){return b.distance-e.distance});return z}else return[]}};
THREE.Rectangle=function(){function b(){k=f-c;h=m-e}var c,e,f,m,k,h,n=!0;this.getX=function(){return c};this.getY=function(){return e};this.getWidth=function(){return k};this.getHeight=function(){return h};this.getLeft=function(){return c};this.getTop=function(){return e};this.getRight=function(){return f};this.getBottom=function(){return m};this.set=function(k,h,v,t){n=!1;c=k;e=h;f=v;m=t;b()};this.addPoint=function(k,h){n?(n=!1,c=k,e=h,f=k,m=h):(c=c<k?c:k,e=e<h?e:h,f=f>k?f:k,m=m>h?m:h);b()};this.add3Points=
function(k,h,v,t,x,w){n?(n=!1,c=k<v?k<x?k:x:v<x?v:x,e=h<t?h<w?h:w:t<w?t:w,f=k>v?k>x?k:x:v>x?v:x,m=h>t?h>w?h:w:t>w?t:w):(c=k<v?k<x?k<c?k:c:x<c?x:c:v<x?v<c?v:c:x<c?x:c,e=h<t?h<w?h<e?h:e:w<e?w:e:t<w?t<e?t:e:w<e?w:e,f=k>v?k>x?k>f?k:f:x>f?x:f:v>x?v>f?v:f:x>f?x:f,m=h>t?h>w?h>m?h:m:w>m?w:m:t>w?t>m?t:m:w>m?w:m);b()};this.addRectangle=function(k){n?(n=!1,c=k.getLeft(),e=k.getTop(),f=k.getRight(),m=k.getBottom()):(c=c<k.getLeft()?c:k.getLeft(),e=e<k.getTop()?e:k.getTop(),f=f>k.getRight()?f:k.getRight(),m=m>
k.getBottom()?m:k.getBottom());b()};this.inflate=function(k){c-=k;e-=k;f+=k;m+=k;b()};this.minSelf=function(k){c=c>k.getLeft()?c:k.getLeft();e=e>k.getTop()?e:k.getTop();f=f<k.getRight()?f:k.getRight();m=m<k.getBottom()?m:k.getBottom();b()};this.intersects=function(b){return Math.min(f,b.getRight())-Math.max(c,b.getLeft())>=0&&Math.min(m,b.getBottom())-Math.max(e,b.getTop())>=0};this.empty=function(){n=!0;m=f=e=c=0;b()};this.isEmpty=function(){return n}};THREE.Matrix3=function(){this.m=[]};
24
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}};
25 26 27 28
THREE.Matrix4=function(b,c,e,f,m,k,h,n,o,u,v,t,x,w,y,A){this.set(b!==void 0?b:1,c||0,e||0,f||0,m||0,k!==void 0?k:1,h||0,n||0,o||0,u||0,v!==void 0?v:1,t||0,x||0,w||0,y||0,A!==void 0?A:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(b,c,e,f,m,k,h,n,o,u,v,t,x,w,y,A){this.n11=b;this.n12=c;this.n13=e;this.n14=f;this.n21=m;this.n22=k;this.n23=h;this.n24=n;this.n31=o;this.n32=u;this.n33=v;this.n34=t;this.n41=x;this.n42=w;this.n43=y;this.n44=A;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,m=THREE.Matrix4.__v2,k=THREE.Matrix4.__v3;k.sub(b,c).normalize();if(k.length()===0)k.z=1;f.cross(e,k).normalize();f.length()===0&&(k.x+=1.0E-4,f.cross(e,k).normalize());m.cross(k,f).normalize();this.n11=f.x;this.n12=m.x;this.n13=k.x;this.n21=f.y;this.n22=m.y;this.n23=k.y;this.n31=f.z;this.n32=m.z;this.n33=k.z;return this},multiplyVector3:function(b){var c=b.x,e=b.y,f=b.z,m=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)*m;
b.y=(this.n21*c+this.n22*e+this.n23*f+this.n24)*m;b.z=(this.n31*c+this.n32*e+this.n33*f+this.n34)*m;return b},multiplyVector4:function(b){var c=b.x,e=b.y,f=b.z,m=b.w;b.x=this.n11*c+this.n12*e+this.n13*f+this.n14*m;b.y=this.n21*c+this.n22*e+this.n23*f+this.n24*m;b.z=this.n31*c+this.n32*e+this.n33*f+this.n34*m;b.w=this.n41*c+this.n42*e+this.n43*f+this.n44*m;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+
29 30
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,m=b.n13,k=b.n14,h=b.n21,n=b.n22,o=b.n23,u=b.n24,v=b.n31,t=b.n32,x=b.n33,w=b.n34,y=b.n41,A=b.n42,z=b.n43,D=b.n44,C=c.n11,F=c.n12,
G=c.n13,N=c.n14,R=c.n21,H=c.n22,J=c.n23,I=c.n24,X=c.n31,E=c.n32,O=c.n33,P=c.n34,U=c.n41,V=c.n42,p=c.n43,ea=c.n44;this.n11=e*C+f*R+m*X+k*U;this.n12=e*F+f*H+m*E+k*V;this.n13=e*G+f*J+m*O+k*p;this.n14=e*N+f*I+m*P+k*ea;this.n21=h*C+n*R+o*X+u*U;this.n22=h*F+n*H+o*E+u*V;this.n23=h*G+n*J+o*O+u*p;this.n24=h*N+n*I+o*P+u*ea;this.n31=v*C+t*R+x*X+w*U;this.n32=v*F+t*H+x*E+w*V;this.n33=v*G+t*J+x*O+w*p;this.n34=v*N+t*I+x*P+w*ea;this.n41=y*C+A*R+z*X+D*U;this.n42=y*F+A*H+z*E+D*V;this.n43=y*G+A*J+z*O+D*p;this.n44=y*
31 32 33
N+A*I+z*P+D*ea;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,m=this.n21,k=this.n22,h=this.n23,n=this.n24,o=this.n31,u=this.n32,v=this.n33,t=this.n34,x=this.n41,w=this.n42,y=this.n43,A=this.n44;return f*h*u*x-e*n*u*x-f*k*v*x+c*n*v*x+e*k*t*x-c*h*t*x-f*h*o*w+e*n*o*w+f*m*v*w-b*n*v*w-e*m*t*w+b*h*t*w+f*k*o*y-c*n*o*y-f*m*u*y+b*n*u*y+c*m*t*y-b*k*t*y-e*k*o*A+c*h*o*A+e*m*u*A-b*h*u*A-c*m*
v*A+b*k*v*A},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=
34 35 36
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,
37 38 39 40 41 42 43 44 45 46 47 48 49
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),m=1-e,k=b.x,h=b.y,n=b.z,o=m*k,u=m*h;this.set(o*k+e,o*h-f*n,o*n+f*h,0,o*h+f*n,u*h+e,u*n-f*k,0,o*n-f*h,u*n+f*k,m*n*n+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,m=b.z,k=Math.cos(e),e=Math.sin(e),h=Math.cos(f),f=Math.sin(f),n=Math.cos(m),m=Math.sin(m);switch(c){case "YXZ":var o=
h*n,u=h*m,v=f*n,t=f*m;this.n11=o+t*e;this.n12=v*e-u;this.n13=k*f;this.n21=k*m;this.n22=k*n;this.n23=-e;this.n31=u*e-v;this.n32=t+o*e;this.n33=k*h;break;case "ZXY":o=h*n;u=h*m;v=f*n;t=f*m;this.n11=o-t*e;this.n12=-k*m;this.n13=v+u*e;this.n21=u+v*e;this.n22=k*n;this.n23=t-o*e;this.n31=-k*f;this.n32=e;this.n33=k*h;break;case "ZYX":o=k*n;u=k*m;v=e*n;t=e*m;this.n11=h*n;this.n12=v*f-u;this.n13=o*f+t;this.n21=h*m;this.n22=t*f+o;this.n23=u*f-v;this.n31=-f;this.n32=e*h;this.n33=k*h;break;case "YZX":o=k*h;u=
k*f;v=e*h;t=e*f;this.n11=h*n;this.n12=t-o*m;this.n13=v*m+u;this.n21=m;this.n22=k*n;this.n23=-e*n;this.n31=-f*n;this.n32=u*m+v;this.n33=o-t*m;break;case "XZY":o=k*h;u=k*f;v=e*h;t=e*f;this.n11=h*n;this.n12=-m;this.n13=f*n;this.n21=o*m+t;this.n22=k*n;this.n23=u*m-v;this.n31=v*m-u;this.n32=e*n;this.n33=t*m+o;break;default:o=k*n,u=k*m,v=e*n,t=e*m,this.n11=h*n,this.n12=-h*m,this.n13=f,this.n21=u+v*f,this.n22=o-t*f,this.n23=-e*h,this.n31=t-o*f,this.n32=v+u*f,this.n33=k*h}return this},setRotationFromQuaternion:function(b){var c=
b.x,e=b.y,f=b.z,m=b.w,k=c+c,h=e+e,n=f+f,b=c*k,o=c*h;c*=n;var u=e*h;e*=n;f*=n;k*=m;h*=m;m*=n;this.n11=1-(u+f);this.n12=o-m;this.n13=c+h;this.n21=o+m;this.n22=1-(b+f);this.n23=e-k;this.n31=c-h;this.n32=e+k;this.n33=1-(b+u);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},compose:function(b,c,e){var f=THREE.Matrix4.__m1,m=THREE.Matrix4.__m2;
f.identity();f.setRotationFromQuaternion(c);m.setScale(e.x,e.y,e.z);this.multiply(f,m);this.n14=b.x;this.n24=b.y;this.n34=b.z;return this},decompose:function(b,c,e){var f=THREE.Matrix4.__v1,m=THREE.Matrix4.__v2,k=THREE.Matrix4.__v3;f.set(this.n11,this.n21,this.n31);m.set(this.n12,this.n22,this.n32);k.set(this.n13,this.n23,this.n33);b=b instanceof THREE.Vector3?b:new THREE.Vector3;c=c instanceof THREE.Quaternion?c:new THREE.Quaternion;e=e instanceof THREE.Vector3?e:new THREE.Vector3;e.x=f.length();
e.y=m.length();e.z=k.length();b.x=this.n14;b.y=this.n24;b.z=this.n34;f=THREE.Matrix4.__m1;f.copy(this);f.n11/=e.x;f.n21/=e.x;f.n31/=e.x;f.n12/=e.y;f.n22/=e.y;f.n32/=e.y;f.n13/=e.z;f.n23/=e.z;f.n33/=e.z;c.setFromRotationMatrix(f);return[b,c,e]},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,m=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*m;this.n23=
b.n23*m;this.n33=b.n33*m}};
THREE.Matrix4.makeInvert=function(b,c){var e=b.n11,f=b.n12,m=b.n13,k=b.n14,h=b.n21,n=b.n22,o=b.n23,u=b.n24,v=b.n31,t=b.n32,x=b.n33,w=b.n34,y=b.n41,A=b.n42,z=b.n43,D=b.n44;c===void 0&&(c=new THREE.Matrix4);c.n11=o*w*A-u*x*A+u*t*z-n*w*z-o*t*D+n*x*D;c.n12=k*x*A-m*w*A-k*t*z+f*w*z+m*t*D-f*x*D;c.n13=m*u*A-k*o*A+k*n*z-f*u*z-m*n*D+f*o*D;c.n14=k*o*t-m*u*t-k*n*x+f*u*x+m*n*w-f*o*w;c.n21=u*x*y-o*w*y-u*v*z+h*w*z+o*v*D-h*x*D;c.n22=m*w*y-k*x*y+k*v*z-e*w*z-m*v*D+e*x*D;c.n23=k*o*y-m*u*y-k*h*z+e*u*z+m*h*D-e*o*D;c.n24=
m*u*v-k*o*v+k*h*x-e*u*x-m*h*w+e*o*w;c.n31=n*w*y-u*t*y+u*v*A-h*w*A-n*v*D+h*t*D;c.n32=k*t*y-f*w*y-k*v*A+e*w*A+f*v*D-e*t*D;c.n33=m*u*y-k*n*y+k*h*A-e*u*A-f*h*D+e*n*D;c.n34=k*n*v-f*u*v-k*h*t+e*u*t+f*h*w-e*n*w;c.n41=o*t*y-n*x*y-o*v*A+h*x*A+n*v*z-h*t*z;c.n42=f*x*y-m*t*y+m*v*A-e*x*A-f*v*z+e*t*z;c.n43=m*n*y-f*o*y-m*h*A+e*o*A+f*h*z-e*n*z;c.n44=f*o*v-m*n*v+m*h*t-e*o*t-f*h*x+e*n*x;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,m=-b.n33*b.n21+b.n31*b.n23,k=b.n32*b.n21-b.n31*b.n22,h=-b.n33*b.n12+b.n32*b.n13,n=b.n33*b.n11-b.n31*b.n13,o=-b.n32*b.n11+b.n31*b.n12,u=b.n23*b.n12-b.n22*b.n13,v=-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*u;b==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");b=1/b;e[0]=b*f;e[1]=b*m;e[2]=b*k;e[3]=b*h;e[4]=b*n;e[5]=b*o;e[6]=b*u;e[7]=b*v;e[8]=b*t;return c};
THREE.Matrix4.makeFrustum=function(b,c,e,f,m,k){var h;h=new THREE.Matrix4;h.n11=2*m/(c-b);h.n12=0;h.n13=(c+b)/(c-b);h.n14=0;h.n21=0;h.n22=2*m/(f-e);h.n23=(f+e)/(f-e);h.n24=0;h.n31=0;h.n32=0;h.n33=-(k+m)/(k-m);h.n34=-2*k*m/(k-m);h.n41=0;h.n42=0;h.n43=-1;h.n44=0;return h};THREE.Matrix4.makePerspective=function(b,c,e,f){var m,b=e*Math.tan(b*Math.PI/360);m=-b;return THREE.Matrix4.makeFrustum(m*c,b*c,m,b,e,f)};
THREE.Matrix4.makeOrtho=function(b,c,e,f,m,k){var h,n,o,u;h=new THREE.Matrix4;n=c-b;o=e-f;u=k-m;h.n11=2/n;h.n12=0;h.n13=0;h.n14=-((c+b)/n);h.n21=0;h.n22=2/o;h.n23=0;h.n24=-((e+f)/o);h.n31=0;h.n32=0;h.n33=-2/u;h.n34=-((k+m)/u);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.__m1=new THREE.Matrix4;THREE.Matrix4.__m2=new THREE.Matrix4;
50 51
THREE.Object3D=function(){this.id=THREE.Object3DCount++;this.name="";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.frustumCulled=!0;this._vector=new THREE.Vector3};
52
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)},add:function(b){if(this.children.indexOf(b)===
53 54
-1){b.parent!==void 0&&b.parent.removeChild(b);b.parent=this;this.children.push(b);for(var c=this;c.parent!==void 0;)c=c.parent;c!==void 0&&c instanceof THREE.Scene&&c.addChildRecurse(b)}},remove:function(b){var c=this,e=this.children.indexOf(b);if(e!==-1){b.parent=void 0;for(this.children.splice(e,1);c.parent!==void 0;)c=c.parent;c!==void 0&&c instanceof THREE.Scene&&c.removeChildRecurse(b)}},getChildByName:function(b,c){var e,f,m;e=0;for(f=this.children.length;e<f;e++){m=this.children[e];if(m.name===
b)return m;if(c&&(m=m.getChildByName(b,c),m!==void 0))return m}},updateMatrix:function(){this.matrix.setPosition(this.position);this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation,this.eulerOrder);if(this.scale.x!==1||this.scale.y!==1||this.scale.z!==1)this.matrix.scale(this.scale),this.boundRadiusScale=Math.max(this.scale.x,Math.max(this.scale.y,this.scale.z));this.matrixWorldNeedsUpdate=!0},update:function(b,c,e){this.matrixAutoUpdate&&
M
Mr.doob 已提交
55 56
this.updateMatrix();if(this.matrixWorldNeedsUpdate||c)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matrixWorldNeedsUpdate=!1,c=!0;for(var b=0,f=this.children.length;b<f;b++)this.children[b].update(this.matrixWorld,c,e)},addChild:function(b){console.warn("DEPRECATED: Object3D.addChild() is now Object3D.add().");this.add(b)},removeChild:function(b){console.warn("DEPRECATED: Object3D.removeChild() is now Object3D.remove().");
this.remove(b)}};THREE.Object3DCount=0;
57
THREE.Projector=function(){function b(){var b=o[n]=o[n]||new THREE.RenderableVertex;n++;return b}function c(b,e){return e.z-b.z}function e(b,e){var c=0,f=1,k=b.z+b.w,m=e.z+e.w,h=-b.z+b.w,n=-e.z+e.w;return k>=0&&m>=0&&h>=0&&n>=0?!0:k<0&&m<0||h<0&&n<0?!1:(k<0?c=Math.max(c,k/(k-m)):m<0&&(f=Math.min(f,k/(k-m))),h<0?c=Math.max(c,h/(h-n)):n<0&&(f=Math.min(f,h/(h-n))),f<c?!1:(b.lerpSelf(e,c),e.lerpSelf(b,1-f),!0))}var f,m,k=[],h,n,o=[],u,v,t=[],x,w=[],y,A,z=[],D,C,F=[],G=[],N=[],R=new THREE.Vector4,H=new THREE.Vector4,
58 59
J=new THREE.Matrix4,I=new THREE.Matrix4,X=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],E=new THREE.Vector4,O=new THREE.Vector4;this.projectVector=function(b,e){J.multiply(e.projectionMatrix,e.matrixWorldInverse);J.multiplyVector3(b);return b};this.unprojectVector=function(b,e){J.multiply(e.matrixWorld,THREE.Matrix4.makeInvert(e.projectionMatrix));J.multiplyVector3(b);return b};this.projectObjects=function(b,e,h){var p,n;m=G.length=0;
p=b.objects;b=0;for(e=p.length;b<e;b++){n=p[b];var t;if(!(t=!n.visible))if(t=n instanceof THREE.Mesh)if(t=n.frustumCulled){a:{t=void 0;for(var w=n.matrixWorld,o=-n.geometry.boundingSphere.radius*Math.max(n.scale.x,Math.max(n.scale.y,n.scale.z)),u=0;u<6;u++)if(t=X[u].x*w.n14+X[u].y*w.n24+X[u].z*w.n34+X[u].w,t<=o){t=!1;break a}t=!0}t=!t}if(!t)t=k[m]=k[m]||new THREE.RenderableObject,m++,f=t,R.copy(n.position),J.multiplyVector3(R),f.object=n,f.z=R.z,G.push(f)}h&&G.sort(c);return G};this.projectScene=
60
function(f,k,m){var p=k.near,G=k.far,R,ka,$,ia,ca,ma,fa,da,T,Y,ga,ja,sa,M,la,pa,qa;C=A=x=v=N.length=0;k.matrixAutoUpdate&&k.update(void 0,!0);f.update(void 0,!1,k);J.multiply(k.projectionMatrix,k.matrixWorldInverse);X[0].set(J.n41-J.n11,J.n42-J.n12,J.n43-J.n13,J.n44-J.n14);X[1].set(J.n41+J.n11,J.n42+J.n12,J.n43+J.n13,J.n44+J.n14);X[2].set(J.n41+J.n21,J.n42+J.n22,J.n43+J.n23,J.n44+J.n24);X[3].set(J.n41-J.n21,J.n42-J.n22,J.n43-J.n23,J.n44-J.n24);X[4].set(J.n41-J.n31,J.n42-J.n32,J.n43-J.n33,J.n44-J.n34);
61 62 63 64 65
X[5].set(J.n41+J.n31,J.n42+J.n32,J.n43+J.n33,J.n44+J.n34);for(R=0;R<6;R++)T=X[R],T.divideScalar(Math.sqrt(T.x*T.x+T.y*T.y+T.z*T.z));T=this.projectObjects(f,k,!0);f=0;for(R=T.length;f<R;f++)if(Y=T[f].object,Y.visible)if(ga=Y.matrixWorld,ja=Y.matrixRotationWorld,sa=Y.materials,M=Y.overdraw,n=0,Y instanceof THREE.Mesh){la=Y.geometry;ia=la.vertices;pa=la.faces;la=la.faceVertexUvs;ka=0;for($=ia.length;ka<$;ka++)h=b(),h.positionWorld.copy(ia[ka].position),ga.multiplyVector3(h.positionWorld),h.positionScreen.copy(h.positionWorld),
J.multiplyVector4(h.positionScreen),h.positionScreen.x/=h.positionScreen.w,h.positionScreen.y/=h.positionScreen.w,h.visible=h.positionScreen.z>p&&h.positionScreen.z<G;ia=0;for(ka=pa.length;ia<ka;ia++){$=pa[ia];if($ instanceof THREE.Face3)if(ca=o[$.a],ma=o[$.b],fa=o[$.c],ca.visible&&ma.visible&&fa.visible&&(Y.doubleSided||Y.flipSided!=(fa.positionScreen.x-ca.positionScreen.x)*(ma.positionScreen.y-ca.positionScreen.y)-(fa.positionScreen.y-ca.positionScreen.y)*(ma.positionScreen.x-ca.positionScreen.x)<
0))da=t[v]=t[v]||new THREE.RenderableFace3,v++,u=da,u.v1.copy(ca),u.v2.copy(ma),u.v3.copy(fa);else continue;else if($ instanceof THREE.Face4)if(ca=o[$.a],ma=o[$.b],fa=o[$.c],da=o[$.d],ca.visible&&ma.visible&&fa.visible&&da.visible&&(Y.doubleSided||Y.flipSided!=((da.positionScreen.x-ca.positionScreen.x)*(ma.positionScreen.y-ca.positionScreen.y)-(da.positionScreen.y-ca.positionScreen.y)*(ma.positionScreen.x-ca.positionScreen.x)<0||(ma.positionScreen.x-fa.positionScreen.x)*(da.positionScreen.y-fa.positionScreen.y)-
(ma.positionScreen.y-fa.positionScreen.y)*(da.positionScreen.x-fa.positionScreen.x)<0)))qa=w[x]=w[x]||new THREE.RenderableFace4,x++,u=qa,u.v1.copy(ca),u.v2.copy(ma),u.v3.copy(fa),u.v4.copy(da);else continue;u.normalWorld.copy($.normal);ja.multiplyVector3(u.normalWorld);u.centroidWorld.copy($.centroid);ga.multiplyVector3(u.centroidWorld);u.centroidScreen.copy(u.centroidWorld);J.multiplyVector3(u.centroidScreen);fa=$.vertexNormals;ca=0;for(ma=fa.length;ca<ma;ca++)da=u.vertexNormalsWorld[ca],da.copy(fa[ca]),
ja.multiplyVector3(da);ca=0;for(ma=la.length;ca<ma;ca++)if(qa=la[ca][ia]){fa=0;for(da=qa.length;fa<da;fa++)u.uvs[ca][fa]=qa[fa]}u.meshMaterials=sa;u.faceMaterials=$.materials;u.overdraw=M;u.z=u.centroidScreen.z;N.push(u)}}else if(Y instanceof THREE.Line){I.multiply(J,ga);ia=Y.geometry.vertices;ca=b();ca.positionScreen.copy(ia[0].position);I.multiplyVector4(ca.positionScreen);ka=1;for($=ia.length;ka<$;ka++)if(ca=b(),ca.positionScreen.copy(ia[ka].position),I.multiplyVector4(ca.positionScreen),ma=o[n-
66
2],E.copy(ca.positionScreen),O.copy(ma.positionScreen),e(E,O))E.multiplyScalar(1/E.w),O.multiplyScalar(1/O.w),ga=z[A]=z[A]||new THREE.RenderableLine,A++,y=ga,y.v1.positionScreen.copy(E),y.v2.positionScreen.copy(O),y.z=Math.max(E.z,O.z),y.materials=Y.materials,N.push(y)}else if(Y instanceof THREE.Particle&&(H.set(Y.matrixWorld.n14,Y.matrixWorld.n24,Y.matrixWorld.n34,1),J.multiplyVector4(H),H.z/=H.w,H.z>0&&H.z<1))ga=F[C]=F[C]||new THREE.RenderableParticle,C++,D=ga,D.x=H.x/H.w,D.y=H.y/H.w,D.z=H.z,D.rotation=
67 68
Y.rotation.z,D.scale.x=Y.scale.x*Math.abs(D.x-(H.x+k.projectionMatrix.n11)/(H.w+k.projectionMatrix.n14)),D.scale.y=Y.scale.y*Math.abs(D.y-(H.y+k.projectionMatrix.n22)/(H.w+k.projectionMatrix.n24)),D.materials=Y.materials,N.push(D);m&&N.sort(c);return N}};THREE.Quaternion=function(b,c,e,f){this.set(b||0,c||0,e||0,f!==void 0?f:1)};
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,m=b.z*c,b=Math.cos(f),f=Math.sin(f),c=Math.cos(-m),m=Math.sin(-m),k=Math.cos(e),e=Math.sin(e),h=b*c,n=f*m;this.w=h*k-n*e;this.x=h*e+n*k;this.y=f*c*k+b*m*e;this.z=b*m*k-f*c*e;return this},setFromAxisAngle:function(b,c){var e=c/2,f=Math.sin(e);
M
Mr.doob 已提交
69 70
this.x=b.x*f;this.y=b.y*f;this.z=b.z*f;this.w=Math.cos(e);return this},setFromRotationMatrix:function(b){var c=Math.pow(b.determinant(),1/3);this.w=Math.sqrt(Math.max(0,c+b.n11+b.n22+b.n33))/2;this.x=Math.sqrt(Math.max(0,c+b.n11-b.n22-b.n33))/2;this.y=Math.sqrt(Math.max(0,c-b.n11+b.n22-b.n33))/2;this.z=Math.sqrt(Math.max(0,c-b.n11-b.n22+b.n33))/2;this.x=b.n32-b.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=b.n13-b.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=b.n21-b.n12<0?-Math.abs(this.z):Math.abs(this.z);
this.normalize();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=
71 72 73 74
this.x,e=this.y,f=this.z,m=this.w,k=b.x,h=b.y,n=b.z,b=b.w;this.x=c*b+m*k+e*n-f*h;this.y=e*b+m*h+f*k-c*n;this.z=f*b+m*n+c*h-e*k;this.w=m*b-c*k-e*h-f*n;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,m=b.z,k=this.x,h=this.y,n=this.z,o=this.w,u=o*e+h*m-n*f,v=o*f+n*e-k*m,t=o*m+k*f-h*e,e=-k*
e-h*f-n*m;c.x=u*o+e*-k+v*-n-t*-h;c.y=v*o+e*-h+t*-k-u*-n;c.z=t*o+e*-n+u*-h-v*-k;return c}};THREE.Quaternion.slerp=function(b,c,e,f){var m=b.w*c.w+b.x*c.x+b.y*c.y+b.z*c.z;if(Math.abs(m)>=1)return e.w=b.w,e.x=b.x,e.y=b.y,e.z=b.z,e;var k=Math.acos(m),h=Math.sqrt(1-m*m);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;m=Math.sin((1-f)*k)/h;f=Math.sin(f*k)/h;e.w=b.w*m+c.w*f;e.x=b.x*m+c.x*f;e.y=b.y*m+c.y*f;e.z=b.z*m+c.z*f;return e};
THREE.Vertex=function(b){this.position=b||new THREE.Vector3};THREE.Face3=function(b,c,e,f,m,k){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=m instanceof THREE.Color?m:new THREE.Color;this.vertexColors=m instanceof Array?m:[];this.vertexTangents=[];this.materials=k instanceof Array?k:[k];this.centroid=new THREE.Vector3};
THREE.Face4=function(b,c,e,f,m,k,h){this.a=b;this.b=c;this.c=e;this.d=f;this.normal=m instanceof THREE.Vector3?m:new THREE.Vector3;this.vertexNormals=m instanceof Array?m:[];this.color=k instanceof THREE.Color?k:new THREE.Color;this.vertexColors=k instanceof Array?k:[];this.vertexTangents=[];this.materials=h instanceof Array?h:[h];this.centroid=new THREE.Vector3};THREE.UV=function(b,c){this.u=b||0;this.v=c||0};
75
THREE.UV.prototype={constructor:THREE.UV,set:function(b,c){this.u=b;this.v=c;return this},copy:function(b){this.u=b.u;this.v=b.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
76
THREE.Geometry=function(){this.id=THREE.GeometryCount++;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.dynamic=this.hasTangents=!1};
77
THREE.Geometry.prototype={constructor:THREE.Geometry,applyMatrix:function(b){var c=new THREE.Matrix4;c.extractRotation(b,new THREE.Vector3(1,1,1));for(var e=0,f=this.vertices.length;e<f;e++)b.multiplyVector3(this.vertices[e].position);e=0;for(f=this.faces.length;e<f;e++){var m=this.faces[e];c.multiplyVector3(m.normal);for(var k=0,h=m.vertexNormals.length;k<h;k++)c.multiplyVector3(m.vertexNormals[k]);b.multiplyVector3(m.centroid)}},computeCentroids:function(){var b,c,e;b=0;for(c=this.faces.length;b<
78
c;b++)e=this.faces[b],e.centroid.set(0,0,0),e instanceof THREE.Face3?(e.centroid.addSelf(this.vertices[e.a].position),e.centroid.addSelf(this.vertices[e.b].position),e.centroid.addSelf(this.vertices[e.c].position),e.centroid.divideScalar(3)):e instanceof THREE.Face4&&(e.centroid.addSelf(this.vertices[e.a].position),e.centroid.addSelf(this.vertices[e.b].position),e.centroid.addSelf(this.vertices[e.c].position),e.centroid.addSelf(this.vertices[e.d].position),e.centroid.divideScalar(4))},computeFaceNormals:function(b){var c,
79
e,f,m,k,h,n=new THREE.Vector3,o=new THREE.Vector3;f=0;for(m=this.faces.length;f<m;f++){k=this.faces[f];if(b&&k.vertexNormals.length){n.set(0,0,0);c=0;for(e=k.vertexNormals.length;c<e;c++)n.addSelf(k.vertexNormals[c]);n.divideScalar(3)}else c=this.vertices[k.a],e=this.vertices[k.b],h=this.vertices[k.c],n.sub(h.position,e.position),o.sub(c.position,e.position),n.crossSelf(o);n.isZero()||n.normalize();k.normal.copy(n)}},computeVertexNormals:function(){var b,c,e,f;if(this.__tmpVertices==void 0){f=this.__tmpVertices=
80 81
Array(this.vertices.length);b=0;for(c=this.vertices.length;b<c;b++)f[b]=new THREE.Vector3;b=0;for(c=this.faces.length;b<c;b++)if(e=this.faces[b],e instanceof THREE.Face3)e.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(e instanceof THREE.Face4)e.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}else{f=this.__tmpVertices;b=0;for(c=this.vertices.length;b<c;b++)f[b].set(0,0,0)}b=0;for(c=this.faces.length;b<c;b++)e=this.faces[b],e instanceof
THREE.Face3?(f[e.a].addSelf(e.normal),f[e.b].addSelf(e.normal),f[e.c].addSelf(e.normal)):e instanceof THREE.Face4&&(f[e.a].addSelf(e.normal),f[e.b].addSelf(e.normal),f[e.c].addSelf(e.normal),f[e.d].addSelf(e.normal));b=0;for(c=this.vertices.length;b<c;b++)f[b].normalize();b=0;for(c=this.faces.length;b<c;b++)e=this.faces[b],e instanceof THREE.Face3?(e.vertexNormals[0].copy(f[e.a]),e.vertexNormals[1].copy(f[e.b]),e.vertexNormals[2].copy(f[e.c])):e instanceof THREE.Face4&&(e.vertexNormals[0].copy(f[e.a]),
82 83
e.vertexNormals[1].copy(f[e.b]),e.vertexNormals[2].copy(f[e.c]),e.vertexNormals[3].copy(f[e.d]))},computeTangents:function(){function b(b,e,c,f,k,m,p){n=b.vertices[e].position;o=b.vertices[c].position;u=b.vertices[f].position;v=h[k];t=h[m];x=h[p];w=o.x-n.x;y=u.x-n.x;A=o.y-n.y;z=u.y-n.y;D=o.z-n.z;C=u.z-n.z;F=t.u-v.u;G=x.u-v.u;N=t.v-v.v;R=x.v-v.v;H=1/(F*R-G*N);E.set((R*w-N*y)*H,(R*A-N*z)*H,(R*D-N*C)*H);O.set((F*y-G*w)*H,(F*z-G*A)*H,(F*C-G*D)*H);I[e].addSelf(E);I[c].addSelf(E);I[f].addSelf(E);X[e].addSelf(O);
X[c].addSelf(O);X[f].addSelf(O)}var c,e,f,m,k,h,n,o,u,v,t,x,w,y,A,z,D,C,F,G,N,R,H,J,I=[],X=[],E=new THREE.Vector3,O=new THREE.Vector3,P=new THREE.Vector3,U=new THREE.Vector3,V=new THREE.Vector3;c=0;for(e=this.vertices.length;c<e;c++)I[c]=new THREE.Vector3,X[c]=new THREE.Vector3;c=0;for(e=this.faces.length;c<e;c++)k=this.faces[c],h=this.faceVertexUvs[0][c],k instanceof THREE.Face3?b(this,k.a,k.b,k.c,0,1,2):k instanceof THREE.Face4&&(b(this,k.a,k.b,k.c,0,1,2),b(this,k.a,k.b,k.d,0,1,3));var p=["a","b",
84
"c","d"];c=0;for(e=this.faces.length;c<e;c++){k=this.faces[c];for(f=0;f<k.vertexNormals.length;f++)V.copy(k.vertexNormals[f]),m=k[p[f]],J=I[m],P.copy(J),P.subSelf(V.multiplyScalar(V.dot(J))).normalize(),U.cross(k.vertexNormals[f],J),m=U.dot(X[m]),m=m<0?-1:1,k.vertexTangents[f]=new THREE.Vector4(P.x,P.y,P.z,m)}this.hasTangents=!0},computeBoundingBox:function(){var b;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,
85
this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var c=1,e=this.vertices.length;c<e;c++){b=this.vertices[c];if(b.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=b.position.x;else if(b.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=b.position.x;if(b.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=b.position.y;else if(b.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=b.position.y;if(b.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=
86 87 88
b.position.z;else if(b.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=b.position.z}}},computeBoundingSphere:function(){for(var b=0,c=0,e=this.vertices.length;c<e;c++)b=Math.max(b,this.vertices[c].position.length());this.boundingSphere={radius:b}},computeEdgeFaces:function(){function b(b,e){return Math.min(b,e)+"_"+Math.max(b,e)}function c(b,e,c){b[e]===void 0&&(b[e]={set:{},array:[]});b[e].set[c]=1;b[e].array.push(c)}var e,f,m,k,h={};e=0;for(f=this.faces.length;e<f;e++)m=this.faces[e],m instanceof
THREE.Face3?(k=b(m.a,m.b),c(h,k,e),k=b(m.b,m.c),c(h,k,e),k=b(m.c,m.a),c(h,k,e)):m instanceof THREE.Face4&&(k=b(m.a,m.b),c(h,k,e),k=b(m.b,m.c),c(h,k,e),k=b(m.c,m.d),c(h,k,e),k=b(m.d,m.a),c(h,k,e));this.vfMap=h;m=0;for(e in h)m++,f=h[e],this.edges.push(f.array)},checkDupVertices:function(){var b={},c={},e,f,m;f=0;for(m=this.vertices.length;f<m;f++)e=this.vertices[f].position,e=[Math.round(e.x*1E3),Math.round(e.y*1E3),Math.round(e.z*1E3)].join("_"),b[e]===void 0?b[e]=f:c[f]=b[e];e=function(b){if(c[b]!==
void 0)return c[b];return b};f=0;for(m=this.faces.length;f<m;f++){b=this.faces[f];if(b instanceof THREE.Face3)b.a=e(b.a),b.b=e(b.b),b.c=e(b.c);if(b instanceof THREE.Face4)b.a=e(b.a),b.b=e(b.b),b.c=e(b.c),b.d=e(b.d)}}};THREE.GeometryCount=0;
89 90 91 92
THREE.Spline=function(b){function c(b,e,c,f,k,m,h){b=(c-b)*0.5;f=(f-e)*0.5;return(2*(e-c)+b+f)*h+(-3*(e-c)-2*b-f)*m+b*k+e}this.points=b;var e=[],f={x:0,y:0,z:0},m,k,h,n,o,u,v,t,x;this.initFromArray=function(b){this.points=[];for(var e=0;e<b.length;e++)this.points[e]={x:b[e][0],y:b[e][1],z:b[e][2]}};this.getPoint=function(b){m=(this.points.length-1)*b;k=Math.floor(m);h=m-k;e[0]=k==0?k:k-1;e[1]=k;e[2]=k>this.points.length-2?k:k+1;e[3]=k>this.points.length-3?k:k+2;u=this.points[e[0]];v=this.points[e[1]];
t=this.points[e[2]];x=this.points[e[3]];n=h*h;o=h*n;f.x=c(u.x,v.x,t.x,x.x,h,n,o);f.y=c(u.y,v.y,t.y,x.y,h,n,o);f.z=c(u.z,v.z,t.z,x.z,h,n,o);return f};this.getControlPointsArray=function(){var b,e,c=this.points.length,f=[];for(b=0;b<c;b++)e=this.points[b],f[b]=[e.x,e.y,e.z];return f};this.getLength=function(b){var e,c,f=e=e=0,k=new THREE.Vector3,m=new THREE.Vector3,h=[],n=0;h[0]=0;b||(b=100);c=this.points.length*b;k.copy(this.points[0]);for(b=1;b<c;b++)e=b/c,position=this.getPoint(e),m.copy(position),
n+=m.distanceTo(k),k.copy(position),e*=this.points.length-1,e=Math.floor(e),e!=f&&(h[e]=n,f=e);h[h.length]=n;return{chunks:h,total:n}};this.reparametrizeByArcLength=function(b){var e,c,f,k,m,h,n=[],t=new THREE.Vector3,u=this.getLength();n.push(t.copy(this.points[0]).clone());for(e=1;e<this.points.length;e++){c=u.chunks[e]-u.chunks[e-1];h=Math.ceil(b*c/u.total);k=(e-1)/(this.points.length-1);m=e/(this.points.length-1);for(c=1;c<h-1;c++)f=k+c*(1/h)*(m-k),position=this.getPoint(f),n.push(t.copy(position).clone());
n.push(t.copy(this.points[e]).clone())}this.points=n}};THREE.Edge=function(b,c,e,f){this.vertices=[b,c];this.vertexIndices=[e,f];this.faces=[];this.faceIndices=[]};THREE.Camera=function(b,c,e,f,m){THREE.Object3D.call(this);this.fov=b||50;this.aspect=c||1;this.near=e!==void 0?e:0.1;this.far=f!==void 0?f:2E3;this.target=m||new THREE.Object3D;this.useTarget=!0;this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=null;this.updateProjectionMatrix()};THREE.Camera.prototype=new THREE.Object3D;
93
THREE.Camera.prototype.constructor=THREE.Camera;THREE.Camera.prototype.supr=THREE.Object3D.prototype;THREE.Camera.prototype.translate=function(b,c){this.matrix.rotateAxis(c);c.multiplyScalar(b);this.position.addSelf(c);this.target.position.addSelf(c)};
M
Mr.doob 已提交
94
THREE.Camera.prototype.updateProjectionMatrix=function(){if(this.fullWidth){var b=this.fullWidth/this.fullHeight,c=Math.tan(this.fov*Math.PI/360)*this.near,e=-c,f=b*e,b=Math.abs(b*c-f),e=Math.abs(c-e);this.projectionMatrix=THREE.Matrix4.makeFrustum(f+this.x*b/this.fullWidth,f+(this.x+this.width)*b/this.fullWidth,c-(this.y+this.height)*e/this.fullHeight,c-this.y*e/this.fullHeight,this.near,this.far)}else this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};
95
THREE.Camera.prototype.setViewOffset=function(b,c,e,f,m,k){this.fullWidth=b;this.fullHeight=c;this.x=e;this.y=f;this.width=m;this.height=k;this.updateProjectionMatrix()};
M
Mr.doob 已提交
96
THREE.Camera.prototype.update=function(b,c,e){if(this.useTarget)this.matrix.lookAt(this.position,this.target.position,this.up),this.matrix.setPosition(this.position),b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse),c=!0;else if(this.matrixAutoUpdate&&this.updateMatrix(),c||this.matrixWorldNeedsUpdate)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=
97
!1,c=!0,THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse);for(b=0;b<this.children.length;b++)this.children[b].update(this.matrixWorld,c,e)};THREE.OrthoCamera=function(b,c,e,f,m,k,h){THREE.Camera.call(this,45,1,m,k,h);this.left=b;this.right=c;this.top=e;this.bottom=f;this.updateProjectionMatrix()};THREE.OrthoCamera.prototype=new THREE.Camera;THREE.OrthoCamera.prototype.constructor=THREE.OrthoCamera;
M
Mr.doob 已提交
98
THREE.OrthoCamera.prototype.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makeOrtho(this.left,this.right,this.top,this.bottom,this.near,this.far)};THREE.Light=function(b){THREE.Object3D.call(this);this.color=new THREE.Color(b)};THREE.Light.prototype=new THREE.Object3D;THREE.Light.prototype.constructor=THREE.Light;THREE.Light.prototype.supr=THREE.Object3D.prototype;THREE.AmbientLight=function(b){THREE.Light.call(this,b)};THREE.AmbientLight.prototype=new THREE.Light;
99 100
THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(b,c,e){THREE.Light.call(this,b);this.position=new THREE.Vector3(0,1,0);this.intensity=c!==void 0?c:1;this.distance=e!==void 0?e:0};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;THREE.PointLight=function(b,c,e){THREE.Light.call(this,b);this.position=new THREE.Vector3(0,0,0);this.intensity=c!==void 0?c:1;this.distance=e!==void 0?e:0};
THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;THREE.SpotLight=function(b,c,e,f){THREE.Light.call(this,b);this.position=new THREE.Vector3(0,1,0);this.target=new THREE.Object3D;this.intensity=c!==void 0?c:1;this.distance=e!==void 0?e:0;this.castShadow=f!==void 0?f:!1};THREE.SpotLight.prototype=new THREE.Light;THREE.SpotLight.prototype.constructor=THREE.SpotLight;
101 102
THREE.Material=function(b){this.id=THREE.MaterialCount++;b=b||{};this.opacity=b.opacity!==void 0?b.opacity:1;this.transparent=b.transparent!==void 0?b.transparent:!1;this.blending=b.blending!==void 0?b.blending:THREE.NormalBlending;this.depthTest=b.depthTest!==void 0?b.depthTest:!0;this.depthWrite=b.depthWrite!==void 0?b.depthWrite:!0;this.polygonOffset=b.polygonOffset!==void 0?b.polygonOffset:!1;this.polygonOffsetFactor=b.polygonOffsetFactor!==void 0?b.polygonOffsetFactor:0;this.polygonOffsetUnits=
b.polygonOffsetUnits!==void 0?b.polygonOffsetUnits:0;this.alphaTest=b.alphaTest!==void 0?b.alphaTest:0};THREE.MaterialCount=0;THREE.NoShading=0;THREE.FlatShading=1;THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;THREE.VertexColors=2;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.MultiplyBlending=3;THREE.AdditiveAlphaBlending=4;
103 104 105 106 107 108 109
THREE.LineBasicMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.linewidth=b.linewidth!==void 0?b.linewidth:1;this.linecap=b.linecap!==void 0?b.linecap:"round";this.linejoin=b.linejoin!==void 0?b.linejoin:"round";this.vertexColors=b.vertexColors?b.vertexColors:!1;this.fog=b.fog!==void 0?b.fog:!0};THREE.LineBasicMaterial.prototype=new THREE.Material;THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
THREE.MeshBasicMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.map=b.map!==void 0?b.map:null;this.lightMap=b.lightMap!==void 0?b.lightMap:null;this.envMap=b.envMap!==void 0?b.envMap:null;this.combine=b.combine!==void 0?b.combine:THREE.MultiplyOperation;this.reflectivity=b.reflectivity!==void 0?b.reflectivity:1;this.refractionRatio=b.refractionRatio!==void 0?b.refractionRatio:0.98;this.fog=b.fog!==void 0?b.fog:
!0;this.shading=b.shading!==void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.wireframeLinecap=b.wireframeLinecap!==void 0?b.wireframeLinecap:"round";this.wireframeLinejoin=b.wireframeLinejoin!==void 0?b.wireframeLinejoin:"round";this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?b.morphTargets:
!1};THREE.MeshBasicMaterial.prototype=new THREE.Material;THREE.MeshBasicMaterial.prototype.constructor=THREE.MeshBasicMaterial;
THREE.MeshLambertMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.map=b.map!==void 0?b.map:null;this.lightMap=b.lightMap!==void 0?b.lightMap:null;this.envMap=b.envMap!==void 0?b.envMap:null;this.combine=b.combine!==void 0?b.combine:THREE.MultiplyOperation;this.reflectivity=b.reflectivity!==void 0?b.reflectivity:1;this.refractionRatio=b.refractionRatio!==void 0?b.refractionRatio:0.98;this.fog=b.fog!==void 0?
b.fog:!0;this.shading=b.shading!==void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.wireframeLinecap=b.wireframeLinecap!==void 0?b.wireframeLinecap:"round";this.wireframeLinejoin=b.wireframeLinejoin!==void 0?b.wireframeLinejoin:"round";this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?
b.morphTargets:!1};THREE.MeshLambertMaterial.prototype=new THREE.Material;THREE.MeshLambertMaterial.prototype.constructor=THREE.MeshLambertMaterial;
110
THREE.MeshPhongMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.ambient=b.ambient!==void 0?new THREE.Color(b.ambient):new THREE.Color(328965);this.specular=b.specular!==void 0?new THREE.Color(b.specular):new THREE.Color(1118481);this.shininess=b.shininess!==void 0?b.shininess:30;this.map=b.map!==void 0?b.map:null;this.lightMap=b.lightMap!==void 0?b.lightMap:null;this.envMap=b.envMap!==void 0?b.envMap:null;
111 112
this.combine=b.combine!==void 0?b.combine:THREE.MultiplyOperation;this.reflectivity=b.reflectivity!==void 0?b.reflectivity:1;this.refractionRatio=b.refractionRatio!==void 0?b.refractionRatio:0.98;this.fog=b.fog!==void 0?b.fog:!0;this.shading=b.shading!==void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.wireframeLinecap=b.wireframeLinecap!==void 0?b.wireframeLinecap:"round";this.wireframeLinejoin=
b.wireframeLinejoin!==void 0?b.wireframeLinejoin:"round";this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?b.morphTargets:!1};THREE.MeshPhongMaterial.prototype=new THREE.Material;THREE.MeshPhongMaterial.prototype.constructor=THREE.MeshPhongMaterial;
113 114
THREE.MeshDepthMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.shading=b.shading!==void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1};THREE.MeshDepthMaterial.prototype=new THREE.Material;THREE.MeshDepthMaterial.prototype.constructor=THREE.MeshDepthMaterial;
THREE.MeshNormalMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.shading=b.shading?b.shading:THREE.FlatShading;this.wireframe=b.wireframe?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth?b.wireframeLinewidth:1};THREE.MeshNormalMaterial.prototype=new THREE.Material;THREE.MeshNormalMaterial.prototype.constructor=THREE.MeshNormalMaterial;THREE.MeshFaceMaterial=function(){};
M
Mr.doob 已提交
115
THREE.MeshShaderMaterial=function(b){console.warn("DEPRECATED: MeshShaderMaterial() is now ShaderMaterial().");return new THREE.ShaderMaterial(b)};
116
THREE.ParticleBasicMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.map=b.map!==void 0?b.map:null;this.size=b.size!==void 0?b.size:1;this.sizeAttenuation=b.sizeAttenuation!==void 0?b.sizeAttenuation:!0;this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.fog=b.fog!==void 0?b.fog:!0};THREE.ParticleBasicMaterial.prototype=new THREE.Material;THREE.ParticleBasicMaterial.prototype.constructor=THREE.ParticleBasicMaterial;
117
THREE.ParticleCanvasMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.program=b.program!==void 0?b.program:function(){}};THREE.ParticleCanvasMaterial.prototype=new THREE.Material;THREE.ParticleCanvasMaterial.prototype.constructor=THREE.ParticleCanvasMaterial;THREE.ParticleDOMMaterial=function(b){THREE.Material.call(this);this.domElement=b};
118 119
THREE.ShaderMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.fragmentShader=b.fragmentShader!==void 0?b.fragmentShader:"void main() {}";this.vertexShader=b.vertexShader!==void 0?b.vertexShader:"void main() {}";this.uniforms=b.uniforms!==void 0?b.uniforms:{};this.attributes=b.attributes;this.shading=b.shading!==void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.fog=b.fog!==
void 0?b.fog:!1;this.lights=b.lights!==void 0?b.lights:!1;this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?b.morphTargets:!1};THREE.ShaderMaterial.prototype=new THREE.Material;THREE.ShaderMaterial.prototype.constructor=THREE.ShaderMaterial;
120
THREE.Texture=function(b,c,e,f,m,k){this.id=THREE.TextureCount++;this.image=b;this.mapping=c!==void 0?c:new THREE.UVMapping;this.wrapS=e!==void 0?e:THREE.ClampToEdgeWrapping;this.wrapT=f!==void 0?f:THREE.ClampToEdgeWrapping;this.magFilter=m!==void 0?m:THREE.LinearFilter;this.minFilter=k!==void 0?k:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.needsUpdate=!1};
121 122
THREE.Texture.prototype={constructor:THREE.Texture,clone:function(){var b=new THREE.Texture(this.image,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter);b.offset.copy(this.offset);b.repeat.copy(this.repeat);return b}};THREE.TextureCount=0;THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;
123
THREE.UnsignedIntType=14;THREE.FloatType=15;THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;THREE.DataTexture=function(b,c,e,f,m,k,h,n,o){THREE.Texture.call(this,null,m,k,h,n,o);this.image={data:b,width:c,height:e};this.format=f!==void 0?f:THREE.RGBAFormat};THREE.DataTexture.prototype=new THREE.Texture;THREE.DataTexture.prototype.constructor=THREE.DataTexture;
A
alteredq 已提交
124
THREE.DataTexture.prototype.clone=function(){var b=new THREE.DataTexture(this.data.slice(0),this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter);b.offset.copy(this.offset);b.repeat.copy(this.repeat);return b};THREE.Particle=function(b){THREE.Object3D.call(this);this.materials=b instanceof Array?b:[b]};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;
125 126
THREE.ParticleSystem=function(b,c){THREE.Object3D.call(this);this.geometry=b;this.materials=c instanceof Array?c:[c];this.sortParticles=!1};THREE.ParticleSystem.prototype=new THREE.Object3D;THREE.ParticleSystem.prototype.constructor=THREE.ParticleSystem;THREE.Line=function(b,c,e){THREE.Object3D.call(this);this.geometry=b;this.materials=c instanceof Array?c:[c];this.type=e!=void 0?e:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;
THREE.Line.prototype.constructor=THREE.Line;
M
Mr.doob 已提交
127 128
THREE.Mesh=function(b,c){THREE.Object3D.call(this);this.geometry=b;this.materials=c&&c.length?c:[c];this.overdraw=!1;if(this.geometry&&(this.geometry.boundingSphere||this.geometry.computeBoundingSphere(),this.boundRadius=b.boundingSphere.radius,this.geometry.morphTargets.length)){this.morphTargetBase=-1;this.morphTargetForcedOrder=[];this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var e=0;e<this.geometry.morphTargets.length;e++)this.morphTargetInfluences.push(0),this.morphTargetDictionary[this.geometry.morphTargets[e].name]=
e}};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.Mesh.prototype.supr=THREE.Object3D.prototype;THREE.Mesh.prototype.getMorphTargetIndexByName=function(b){if(this.morphTargetDictionary[b]!==void 0)return this.morphTargetDictionary[b];console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+b+" does not exist. Returning 0.");return 0};
129
THREE.Bone=function(b){THREE.Object3D.call(this);this.skin=b;this.skinMatrix=new THREE.Matrix4;this.hasNoneBoneChildren=!1};THREE.Bone.prototype=new THREE.Object3D;THREE.Bone.prototype.constructor=THREE.Bone;THREE.Bone.prototype.supr=THREE.Object3D.prototype;
130
THREE.Bone.prototype.update=function(b,c,e){this.matrixAutoUpdate&&(c|=this.updateMatrix());if(c||this.matrixWorldNeedsUpdate)b?this.skinMatrix.multiply(b,this.matrix):this.skinMatrix.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,c=!0;var f,m=this.children.length;if(this.hasNoneBoneChildren){this.matrixWorld.multiply(this.skin.matrixWorld,this.skinMatrix);for(f=0;f<m;f++)b=this.children[f],b instanceof THREE.Bone?b.update(this.skinMatrix,c,e):b.update(this.matrixWorld,!0,e)}else for(f=0;f<m;f++)this.children[f].update(this.skinMatrix,
M
Mr.doob 已提交
131
c,e)};THREE.Bone.prototype.addChild=function(b){if(this.children.indexOf(b)===-1&&(b.parent!==void 0&&b.parent.removeChild(b),b.parent=this,this.children.push(b),!(b instanceof THREE.Bone)))this.hasNoneBoneChildren=!0};
132 133 134
THREE.SkinnedMesh=function(b,c){THREE.Mesh.call(this,b,c);this.identityMatrix=new THREE.Matrix4;this.bones=[];this.boneMatrices=[];var e,f,m,k,h,n;if(this.geometry.bones!==void 0){for(e=0;e<this.geometry.bones.length;e++)m=this.geometry.bones[e],k=m.pos,h=m.rotq,n=m.scl,f=this.addBone(),f.name=m.name,f.position.set(k[0],k[1],k[2]),f.quaternion.set(h[0],h[1],h[2],h[3]),f.useQuaternion=!0,n!==void 0?f.scale.set(n[0],n[1],n[2]):f.scale.set(1,1,1);for(e=0;e<this.bones.length;e++)m=this.geometry.bones[e],
f=this.bones[e],m.parent===-1?this.addChild(f):this.bones[m.parent].addChild(f);this.boneMatrices=new Float32Array(16*this.bones.length);this.pose()}};THREE.SkinnedMesh.prototype=new THREE.Mesh;THREE.SkinnedMesh.prototype.constructor=THREE.SkinnedMesh;
THREE.SkinnedMesh.prototype.update=function(b,c,e){if(this.visible){this.matrixAutoUpdate&&(c|=this.updateMatrix());if(c||this.matrixWorldNeedsUpdate)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,c=!0;var f,m=this.children.length;for(f=0;f<m;f++)b=this.children[f],b instanceof THREE.Bone?b.update(this.identityMatrix,!1,e):b.update(this.matrixWorld,c,e);e=this.bones.length;ba=this.bones;bm=this.boneMatrices;for(c=0;c<e;c++)ba[c].skinMatrix.flattenToArrayOffset(bm,
135
c*16)}};THREE.SkinnedMesh.prototype.addBone=function(b){b===void 0&&(b=new THREE.Bone(this));this.bones.push(b);return b};
136 137
THREE.SkinnedMesh.prototype.pose=function(){this.update(void 0,!0);for(var b,c=[],e=0;e<this.bones.length;e++)b=this.bones[e],c.push(THREE.Matrix4.makeInvert(b.skinMatrix)),b.skinMatrix.flattenToArrayOffset(this.boneMatrices,e*16);if(this.geometry.skinVerticesA===void 0){this.geometry.skinVerticesA=[];this.geometry.skinVerticesB=[];var f;for(b=0;b<this.geometry.skinIndices.length;b++){var e=this.geometry.vertices[b].position,m=this.geometry.skinIndices[b].x,k=this.geometry.skinIndices[b].y;f=new THREE.Vector3(e.x,
e.y,e.z);this.geometry.skinVerticesA.push(c[m].multiplyVector3(f));f=new THREE.Vector3(e.x,e.y,e.z);this.geometry.skinVerticesB.push(c[k].multiplyVector3(f));this.geometry.skinWeights[b].x+this.geometry.skinWeights[b].y!==1&&(e=(1-(this.geometry.skinWeights[b].x+this.geometry.skinWeights[b].y))*0.5,this.geometry.skinWeights[b].x+=e,this.geometry.skinWeights[b].y+=e)}}};THREE.Ribbon=function(b,c){THREE.Object3D.call(this);this.geometry=b;this.materials=c instanceof Array?c:[c]};
M
Mr.doob 已提交
138
THREE.Ribbon.prototype=new THREE.Object3D;THREE.Ribbon.prototype.constructor=THREE.Ribbon;THREE.LOD=function(){THREE.Object3D.call(this);this.LODs=[]};THREE.LOD.prototype=new THREE.Object3D;THREE.LOD.prototype.constructor=THREE.LOD;THREE.LOD.prototype.supr=THREE.Object3D.prototype;THREE.LOD.prototype.addLevel=function(b,c){c===void 0&&(c=0);for(var c=Math.abs(c),e=0;e<this.LODs.length;e++)if(c<this.LODs[e].visibleAtDistance)break;this.LODs.splice(e,0,{visibleAtDistance:c,object3D:b});this.add(b)};
M
Mr.doob 已提交
139
THREE.LOD.prototype.update=function(b,c,e){this.matrixAutoUpdate&&(c|=this.updateMatrix());if(c||this.matrixWorldNeedsUpdate)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,c=!0;if(this.LODs.length>1){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.length;f++)if(b>=this.LODs[f].visibleAtDistance)this.LODs[f-1].object3D.visible=!1,
M
Mr.doob 已提交
140
this.LODs[f].object3D.visible=!0;else break;for(;f<this.LODs.length;f++)this.LODs[f].object3D.visible=!1}for(b=0;b<this.children.length;b++)this.children[b].update(this.matrixWorld,c,e)};
A
alteredq 已提交
141 142 143 144
THREE.Sprite=function(b){THREE.Object3D.call(this);this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.map=b.map instanceof THREE.Texture?b.map:THREE.ImageUtils.loadTexture(b.map);this.blending=b.blending!==void 0?b.blending:THREE.NormalBlending;this.useScreenCoordinates=b.useScreenCoordinates!==void 0?b.useScreenCoordinates:!0;this.mergeWith3D=b.mergeWith3D!==void 0?b.mergeWith3D:!this.useScreenCoordinates;this.affectedByDistance=b.affectedByDistance!==void 0?b.affectedByDistance:
!this.useScreenCoordinates;this.scaleByViewport=b.scaleByViewport!==void 0?b.scaleByViewport:!this.affectedByDistance;this.alignment=b.alignment instanceof THREE.Vector2?b.alignment:THREE.SpriteAlignment.center;this.rotation3d=this.rotation;this.rotation=0;this.opacity=1;this.uvOffset=new THREE.Vector2(0,0);this.uvScale=new THREE.Vector2(1,1)};THREE.Sprite.prototype=new THREE.Object3D;THREE.Sprite.prototype.constructor=THREE.Sprite;THREE.Sprite.prototype.supr=THREE.Object3D.prototype;
THREE.Sprite.prototype.updateMatrix=function(){this.matrix.setPosition(this.position);this.rotation3d.set(0,0,this.rotation);this.matrix.setRotationFromEuler(this.rotation3d);if(this.scale.x!==1||this.scale.y!==1)this.matrix.scale(this.scale),this.boundRadiusScale=Math.max(this.scale.x,this.scale.y);this.matrixWorldNeedsUpdate=!0};THREE.SpriteAlignment={};THREE.SpriteAlignment.topLeft=new THREE.Vector2(1,-1);THREE.SpriteAlignment.topCenter=new THREE.Vector2(0,-1);
THREE.SpriteAlignment.topRight=new THREE.Vector2(-1,-1);THREE.SpriteAlignment.centerLeft=new THREE.Vector2(1,0);THREE.SpriteAlignment.center=new THREE.Vector2(0,0);THREE.SpriteAlignment.centerRight=new THREE.Vector2(-1,0);THREE.SpriteAlignment.bottomLeft=new THREE.Vector2(1,1);THREE.SpriteAlignment.bottomCenter=new THREE.Vector2(0,1);THREE.SpriteAlignment.bottomRight=new THREE.Vector2(-1,1);
145
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.overrideMaterial=this.fog=null;this.objects=[];this.lights=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.add=function(b){this.supr.add.call(this,b);this.addChildRecurse(b)};
M
Mr.doob 已提交
146 147 148 149
THREE.Scene.prototype.addChildRecurse=function(b){if(b instanceof THREE.Light)this.lights.indexOf(b)===-1&&this.lights.push(b);else if(!(b instanceof THREE.Camera||b instanceof THREE.Bone)&&this.objects.indexOf(b)===-1){this.objects.push(b);this.__objectsAdded.push(b);var c=this.__objectsRemoved.indexOf(b);c!==-1&&this.__objectsRemoved.splice(c,1)}for(c=0;c<b.children.length;c++)this.addChildRecurse(b.children[c])};THREE.Scene.prototype.remove=function(b){this.supr.remove.call(this,b);this.removeChildRecurse(b)};
THREE.Scene.prototype.removeChildRecurse=function(b){if(b instanceof THREE.Light){var c=this.lights.indexOf(b);c!==-1&&this.lights.splice(c,1)}else b instanceof THREE.Camera||(c=this.objects.indexOf(b),c!==-1&&(this.objects.splice(c,1),this.__objectsRemoved.push(b),c=this.__objectsAdded.indexOf(b),c!==-1&&this.__objectsAdded.splice(c,1)));for(c=0;c<b.children.length;c++)this.removeChildRecurse(b.children[c])};
THREE.Scene.prototype.addChild=function(b){console.warn("DEPRECATED: Scene.addChild() is now Scene.add().");this.add(b)};THREE.Scene.prototype.addObject=function(b){console.warn("DEPRECATED: Scene.addObject() is now Scene.add().");this.add(b)};THREE.Scene.prototype.addLight=function(b){console.warn("DEPRECATED: Scene.addLight() is now Scene.add().");this.add(b)};THREE.Scene.prototype.removeChild=function(b){console.warn("DEPRECATED: Scene.removeChild() is now Scene.remove().");this.remove(b)};
THREE.Scene.prototype.removeObject=function(b){console.warn("DEPRECATED: Scene.removeObject() is now Scene.remove().");this.remove(b)};THREE.Scene.prototype.removeLight=function(b){console.warn("DEPRECATED: Scene.removeLight() is now Scene.remove().");this.remove(b)};THREE.Fog=function(b,c,e){this.color=new THREE.Color(b);this.near=c!==void 0?c:1;this.far=e!==void 0?e:1E3};THREE.FogExp2=function(b,c){this.color=new THREE.Color(b);this.density=c!==void 0?c:2.5E-4};
150
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var b=null,c=new THREE.Projector,e,f,m,k;this.domElement=document.createElement("div");this.setSize=function(b,c){e=b;f=c;m=e/2;k=f/2};this.render=function(e,f){var o,u,v,t,x,w,y,A;b=c.projectScene(e,f);o=0;for(u=b.length;o<u;o++)if(x=b[o],x instanceof THREE.RenderableParticle){y=x.x*m+m;A=x.y*k+k;v=0;for(t=x.material.length;v<t;v++)if(w=x.material[v],w instanceof THREE.ParticleDOMMaterial)w=w.domElement,w.style.left=y+"px",w.style.top=A+"px"}}};
151 152
THREE.CanvasRenderer=function(b){function c(b){if(z!=b)w.globalAlpha=z=b}function e(b){if(D!=b){switch(b){case THREE.NormalBlending:w.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:w.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:w.globalCompositeOperation="darker"}D=b}}function f(b){if(C!=b)w.strokeStyle=C=b}function m(b){if(F!=b)w.fillStyle=F=b}var k=this,h=null,n=new THREE.Projector,b=b||{},o=b.canvas!==void 0?b.canvas:document.createElement("canvas"),
u,v,t,x,w=o.getContext("2d"),y=new THREE.Color(0),A=0,z=1,D=0,C=null,F=null,G=null,N=null,R=null,H,J,I,X,E=new THREE.RenderableVertex,O=new THREE.RenderableVertex,P,U,V,p,ea,S,ka,$,ia,ca,ma,fa,da=new THREE.Color(0),T=new THREE.Color(0),Y=new THREE.Color(0),ga=new THREE.Color(0),ja=new THREE.Color(0),sa=[],M,la,pa,qa,wa,ua,Da,za,Ba,Fa,L=new THREE.Rectangle,aa=new THREE.Rectangle,W=new THREE.Rectangle,oa=!1,ha=new THREE.Color,ra=new THREE.Color,Ca=new THREE.Color,va=new THREE.Color,na=new THREE.Vector3,
153
Ia,xa,Ka,Aa,Ga,Z,b=16;Ia=document.createElement("canvas");Ia.width=Ia.height=2;xa=Ia.getContext("2d");xa.fillStyle="rgba(0,0,0,1)";xa.fillRect(0,0,2,2);Ka=xa.getImageData(0,0,2,2);Aa=Ka.data;Ga=document.createElement("canvas");Ga.width=Ga.height=b;Z=Ga.getContext("2d");Z.translate(-b/2,-b/2);Z.scale(b,b);b--;this.domElement=o;this.sortElements=this.sortObjects=this.autoClear=!0;this.info={render:{vertices:0,faces:0}};this.setSize=function(b,e){u=b;v=e;t=Math.floor(u/2);x=Math.floor(v/2);o.width=u;
154
o.height=v;L.set(-t,-x,t,x);aa.set(-t,-x,t,x);z=1;D=0;R=N=G=F=C=null};this.setClearColor=function(b,e){y.copy(b);A=e;aa.set(-t,-x,t,x)};this.setClearColorHex=function(b,e){y.setHex(b);A=e;aa.set(-t,-x,t,x)};this.clear=function(){w.setTransform(1,0,0,-1,t,x);aa.isEmpty()||(aa.minSelf(L),aa.inflate(2),A<1&&w.clearRect(Math.floor(aa.getX()),Math.floor(aa.getY()),Math.floor(aa.getWidth()),Math.floor(aa.getHeight())),A>0&&(e(THREE.NormalBlending),c(1),m("rgba("+Math.floor(y.r*255)+","+Math.floor(y.g*255)+
155 156 157
","+Math.floor(y.b*255)+","+A+")"),w.fillRect(Math.floor(aa.getX()),Math.floor(aa.getY()),Math.floor(aa.getWidth()),Math.floor(aa.getHeight()))),aa.empty())};this.render=function(b,u){function o(b){var e,c,f,k=b.lights;ra.setRGB(0,0,0);Ca.setRGB(0,0,0);va.setRGB(0,0,0);b=0;for(e=k.length;b<e;b++)c=k[b],f=c.color,c instanceof THREE.AmbientLight?(ra.r+=f.r,ra.g+=f.g,ra.b+=f.b):c instanceof THREE.DirectionalLight?(Ca.r+=f.r,Ca.g+=f.g,Ca.b+=f.b):c instanceof THREE.PointLight&&(va.r+=f.r,va.g+=f.g,va.b+=
f.b)}function v(b,e,c,f){var k,m,h,p,n=b.lights,b=0;for(k=n.length;b<k;b++)m=n[b],h=m.color,m instanceof THREE.DirectionalLight?(p=c.dot(m.position),p<=0||(p*=m.intensity,f.r+=h.r*p,f.g+=h.g*p,f.b+=h.b*p)):m instanceof THREE.PointLight&&(p=c.dot(na.sub(m.position,e).normalize()),p<=0||(p*=m.distance==0?1:1-Math.min(e.distanceTo(m.position)/m.distance,1),p!=0&&(p*=m.intensity,f.r+=h.r*p,f.g+=h.g*p,f.b+=h.b*p)))}function Xa(b,k,h){c(h.opacity);e(h.blending);var p,n,u,o,Ea,v;if(h instanceof THREE.ParticleBasicMaterial){if(h.map)o=
h.map.image,Ea=o.width>>1,v=o.height>>1,h=k.scale.x*t,u=k.scale.y*x,p=h*Ea,n=u*v,W.set(b.x-p,b.y-n,b.x+p,b.y+n),L.intersects(W)&&(w.save(),w.translate(b.x,b.y),w.rotate(-k.rotation),w.scale(h,-u),w.translate(-Ea,-v),w.drawImage(o,0,0),w.restore())}else h instanceof THREE.ParticleCanvasMaterial&&(p=k.scale.x*t,n=k.scale.y*x,W.set(b.x-p,b.y-n,b.x+p,b.y+n),L.intersects(W)&&(f(h.color.getContextStyle()),m(h.color.getContextStyle()),w.save(),w.translate(b.x,b.y),w.rotate(-k.rotation),w.scale(p,n),h.program(w),
158 159 160 161
w.restore()))}function y(b,k,m,h){c(h.opacity);e(h.blending);w.beginPath();w.moveTo(b.positionScreen.x,b.positionScreen.y);w.lineTo(k.positionScreen.x,k.positionScreen.y);w.closePath();if(h instanceof THREE.LineBasicMaterial){b=h.linewidth;if(G!=b)w.lineWidth=G=b;b=h.linecap;if(N!=b)w.lineCap=N=b;b=h.linejoin;if(R!=b)w.lineJoin=R=b;f(h.color.getContextStyle());w.stroke();W.inflate(h.linewidth*2)}}function z(b,f,h,m,n,t,o,w,x){k.info.render.vertices+=3;k.info.render.faces++;c(w.opacity);e(w.blending);
P=b.positionScreen.x;U=b.positionScreen.y;V=f.positionScreen.x;p=f.positionScreen.y;ea=h.positionScreen.x;S=h.positionScreen.y;D(P,U,V,p,ea,S);if(w instanceof THREE.MeshBasicMaterial)if(w.map)w.map.mapping instanceof THREE.UVMapping&&(qa=o.uvs[0],ab(P,U,V,p,ea,S,qa[m].u,qa[m].v,qa[n].u,qa[n].v,qa[t].u,qa[t].v,w.map));else if(w.envMap){if(w.envMap.mapping instanceof THREE.SphericalReflectionMapping)b=u.matrixWorldInverse,na.copy(o.vertexNormalsWorld[0]),wa=(na.x*b.n11+na.y*b.n12+na.z*b.n13)*0.5+0.5,
ua=-(na.x*b.n21+na.y*b.n22+na.z*b.n23)*0.5+0.5,na.copy(o.vertexNormalsWorld[1]),Da=(na.x*b.n11+na.y*b.n12+na.z*b.n13)*0.5+0.5,za=-(na.x*b.n21+na.y*b.n22+na.z*b.n23)*0.5+0.5,na.copy(o.vertexNormalsWorld[2]),Ba=(na.x*b.n11+na.y*b.n12+na.z*b.n13)*0.5+0.5,Fa=-(na.x*b.n21+na.y*b.n22+na.z*b.n23)*0.5+0.5,ab(P,U,V,p,ea,S,wa,ua,Da,za,Ba,Fa,w.envMap)}else w.wireframe?F(w.color,w.wireframeLinewidth,w.wireframeLinecap,w.wireframeLinejoin):Na(w.color);else if(w instanceof THREE.MeshLambertMaterial)w.map&&!w.wireframe&&
(w.map.mapping instanceof THREE.UVMapping&&(qa=o.uvs[0],ab(P,U,V,p,ea,S,qa[m].u,qa[m].v,qa[n].u,qa[n].v,qa[t].u,qa[t].v,w.map)),e(THREE.SubtractiveBlending)),oa?!w.wireframe&&w.shading==THREE.SmoothShading&&o.vertexNormalsWorld.length==3?(T.r=Y.r=ga.r=ra.r,T.g=Y.g=ga.g=ra.g,T.b=Y.b=ga.b=ra.b,v(x,o.v1.positionWorld,o.vertexNormalsWorld[0],T),v(x,o.v2.positionWorld,o.vertexNormalsWorld[1],Y),v(x,o.v3.positionWorld,o.vertexNormalsWorld[2],ga),T.r=Math.max(0,Math.min(w.color.r*T.r,1)),T.g=Math.max(0,
162
Math.min(w.color.g*T.g,1)),T.b=Math.max(0,Math.min(w.color.b*T.b,1)),Y.r=Math.max(0,Math.min(w.color.r*Y.r,1)),Y.g=Math.max(0,Math.min(w.color.g*Y.g,1)),Y.b=Math.max(0,Math.min(w.color.b*Y.b,1)),ga.r=Math.max(0,Math.min(w.color.r*ga.r,1)),ga.g=Math.max(0,Math.min(w.color.g*ga.g,1)),ga.b=Math.max(0,Math.min(w.color.b*ga.b,1)),ja.r=(Y.r+ga.r)*0.5,ja.g=(Y.g+ga.g)*0.5,ja.b=(Y.b+ga.b)*0.5,pa=Ya(T,Y,ga,ja),Ua(P,U,V,p,ea,S,0,0,1,0,0,1,pa)):(ha.r=ra.r,ha.g=ra.g,ha.b=ra.b,v(x,o.centroidWorld,o.normalWorld,
163 164 165
ha),da.r=Math.max(0,Math.min(w.color.r*ha.r,1)),da.g=Math.max(0,Math.min(w.color.g*ha.g,1)),da.b=Math.max(0,Math.min(w.color.b*ha.b,1)),w.wireframe?F(da,w.wireframeLinewidth,w.wireframeLinecap,w.wireframeLinejoin):Na(da)):w.wireframe?F(w.color,w.wireframeLinewidth,w.wireframeLinecap,w.wireframeLinejoin):Na(w.color);else if(w instanceof THREE.MeshDepthMaterial)M=u.near,la=u.far,T.r=T.g=T.b=1-Qa(b.positionScreen.z,M,la),Y.r=Y.g=Y.b=1-Qa(f.positionScreen.z,M,la),ga.r=ga.g=ga.b=1-Qa(h.positionScreen.z,
M,la),ja.r=(Y.r+ga.r)*0.5,ja.g=(Y.g+ga.g)*0.5,ja.b=(Y.b+ga.b)*0.5,pa=Ya(T,Y,ga,ja),Ua(P,U,V,p,ea,S,0,0,1,0,0,1,pa);else if(w instanceof THREE.MeshNormalMaterial)da.r=Va(o.normalWorld.x),da.g=Va(o.normalWorld.y),da.b=Va(o.normalWorld.z),w.wireframe?F(da,w.wireframeLinewidth,w.wireframeLinecap,w.wireframeLinejoin):Na(da)}function A(b,f,h,m,n,t,w,o,x){k.info.render.vertices+=4;k.info.render.faces++;c(o.opacity);e(o.blending);if(o.map||o.envMap)z(b,f,m,0,1,3,w,o,x),z(n,h,t,1,2,3,w,o,x);else if(P=b.positionScreen.x,
U=b.positionScreen.y,V=f.positionScreen.x,p=f.positionScreen.y,ea=h.positionScreen.x,S=h.positionScreen.y,ka=m.positionScreen.x,$=m.positionScreen.y,ia=n.positionScreen.x,ca=n.positionScreen.y,ma=t.positionScreen.x,fa=t.positionScreen.y,o instanceof THREE.MeshBasicMaterial)C(P,U,V,p,ea,S,ka,$),o.wireframe?F(o.color,o.wireframeLinewidth,o.wireframeLinecap,o.wireframeLinejoin):Na(o.color);else if(o instanceof THREE.MeshLambertMaterial)oa?!o.wireframe&&o.shading==THREE.SmoothShading&&w.vertexNormalsWorld.length==
166 167
4?(T.r=Y.r=ga.r=ja.r=ra.r,T.g=Y.g=ga.g=ja.g=ra.g,T.b=Y.b=ga.b=ja.b=ra.b,v(x,w.v1.positionWorld,w.vertexNormalsWorld[0],T),v(x,w.v2.positionWorld,w.vertexNormalsWorld[1],Y),v(x,w.v4.positionWorld,w.vertexNormalsWorld[3],ga),v(x,w.v3.positionWorld,w.vertexNormalsWorld[2],ja),T.r=Math.max(0,Math.min(o.color.r*T.r,1)),T.g=Math.max(0,Math.min(o.color.g*T.g,1)),T.b=Math.max(0,Math.min(o.color.b*T.b,1)),Y.r=Math.max(0,Math.min(o.color.r*Y.r,1)),Y.g=Math.max(0,Math.min(o.color.g*Y.g,1)),Y.b=Math.max(0,Math.min(o.color.b*
Y.b,1)),ga.r=Math.max(0,Math.min(o.color.r*ga.r,1)),ga.g=Math.max(0,Math.min(o.color.g*ga.g,1)),ga.b=Math.max(0,Math.min(o.color.b*ga.b,1)),ja.r=Math.max(0,Math.min(o.color.r*ja.r,1)),ja.g=Math.max(0,Math.min(o.color.g*ja.g,1)),ja.b=Math.max(0,Math.min(o.color.b*ja.b,1)),pa=Ya(T,Y,ga,ja),D(P,U,V,p,ka,$),Ua(P,U,V,p,ka,$,0,0,1,0,0,1,pa),D(ia,ca,ea,S,ma,fa),Ua(ia,ca,ea,S,ma,fa,1,0,1,1,0,1,pa)):(ha.r=ra.r,ha.g=ra.g,ha.b=ra.b,v(x,w.centroidWorld,w.normalWorld,ha),da.r=Math.max(0,Math.min(o.color.r*ha.r,
168 169 170 171 172
1)),da.g=Math.max(0,Math.min(o.color.g*ha.g,1)),da.b=Math.max(0,Math.min(o.color.b*ha.b,1)),C(P,U,V,p,ea,S,ka,$),o.wireframe?F(da,o.wireframeLinewidth,o.wireframeLinecap,o.wireframeLinejoin):Na(da)):(C(P,U,V,p,ea,S,ka,$),o.wireframe?F(o.color,o.wireframeLinewidth,o.wireframeLinecap,o.wireframeLinejoin):Na(o.color));else if(o instanceof THREE.MeshNormalMaterial)da.r=Va(w.normalWorld.x),da.g=Va(w.normalWorld.y),da.b=Va(w.normalWorld.z),C(P,U,V,p,ea,S,ka,$),o.wireframe?F(da,o.wireframeLinewidth,o.wireframeLinecap,
o.wireframeLinejoin):Na(da);else if(o instanceof THREE.MeshDepthMaterial)M=u.near,la=u.far,T.r=T.g=T.b=1-Qa(b.positionScreen.z,M,la),Y.r=Y.g=Y.b=1-Qa(f.positionScreen.z,M,la),ga.r=ga.g=ga.b=1-Qa(m.positionScreen.z,M,la),ja.r=ja.g=ja.b=1-Qa(h.positionScreen.z,M,la),pa=Ya(T,Y,ga,ja),D(P,U,V,p,ka,$),Ua(P,U,V,p,ka,$,0,0,1,0,0,1,pa),D(ia,ca,ea,S,ma,fa),Ua(ia,ca,ea,S,ma,fa,1,0,1,1,0,1,pa)}function D(b,e,c,f,k,h){w.beginPath();w.moveTo(b,e);w.lineTo(c,f);w.lineTo(k,h);w.lineTo(b,e);w.closePath()}function C(b,
e,c,f,k,h,m,p){w.beginPath();w.moveTo(b,e);w.lineTo(c,f);w.lineTo(k,h);w.lineTo(m,p);w.lineTo(b,e);w.closePath()}function F(b,e,c,k){if(G!=e)w.lineWidth=G=e;if(N!=c)w.lineCap=N=c;if(R!=k)w.lineJoin=R=k;f(b.getContextStyle());w.stroke();W.inflate(e*2)}function Na(b){m(b.getContextStyle());w.fill()}function ab(b,e,c,f,k,h,p,n,o,t,u,Ea,v){if(v.image.width!=0){if(v.needsUpdate==!0||sa[v.id]==void 0){var x=v.wrapS==THREE.RepeatWrapping,L=v.wrapT==THREE.RepeatWrapping;sa[v.id]=w.createPattern(v.image,x&&
L?"repeat":x&&!L?"repeat-x":!x&&L?"repeat-y":"no-repeat");v.needsUpdate=!1}m(sa[v.id]);var x=v.offset.x/v.repeat.x,L=v.offset.y/v.repeat.y,Xa=(v.image.width-1)*v.repeat.x,v=(v.image.height-1)*v.repeat.y,p=(p+x)*Xa,n=(n+L)*v,o=(o+x)*Xa,t=(t+L)*v,u=(u+x)*Xa,Ea=(Ea+L)*v;c-=b;f-=e;k-=b;h-=e;o-=p;t-=n;u-=p;Ea-=n;x=1/(o*Ea-u*t);v=(Ea*c-t*k)*x;t=(Ea*f-t*h)*x;c=(o*k-u*c)*x;f=(o*h-u*f)*x;b=b-v*p-c*n;e=e-t*p-f*n;w.save();w.transform(v,t,c,f,b,e);w.fill();w.restore()}}function Ua(b,e,c,f,k,h,m,p,n,o,t,u,Ea){var v,
x;v=Ea.width-1;x=Ea.height-1;m*=v;p*=x;n*=v;o*=x;t*=v;u*=x;c-=b;f-=e;k-=b;h-=e;n-=m;o-=p;t-=m;u-=p;x=1/(n*u-t*o);v=(u*c-o*k)*x;o=(u*f-o*h)*x;c=(n*k-t*c)*x;f=(n*h-t*f)*x;b=b-v*m-c*p;e=e-o*m-f*p;w.save();w.transform(v,o,c,f,b,e);w.clip();w.drawImage(Ea,0,0);w.restore()}function Ya(b,e,c,f){var k=~~(b.r*255),h=~~(b.g*255),b=~~(b.b*255),m=~~(e.r*255),p=~~(e.g*255),e=~~(e.b*255),n=~~(c.r*255),o=~~(c.g*255),c=~~(c.b*255),t=~~(f.r*255),w=~~(f.g*255),f=~~(f.b*255);Aa[0]=k<0?0:k>255?255:k;Aa[1]=h<0?0:h>255?
173 174 175 176 177 178
255:h;Aa[2]=b<0?0:b>255?255:b;Aa[4]=m<0?0:m>255?255:m;Aa[5]=p<0?0:p>255?255:p;Aa[6]=e<0?0:e>255?255:e;Aa[8]=n<0?0:n>255?255:n;Aa[9]=o<0?0:o>255?255:o;Aa[10]=c<0?0:c>255?255:c;Aa[12]=t<0?0:t>255?255:t;Aa[13]=w<0?0:w>255?255:w;Aa[14]=f<0?0:f>255?255:f;xa.putImageData(Ka,0,0);Z.drawImage(Ia,0,0);return Ga}function Qa(b,e,c){b=(b-e)/(c-e);return b*b*(3-2*b)}function Va(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}function Oa(b,e){var c=e.x-b.x,f=e.y-b.y,k=c*c+f*f;k!=0&&(k=1/Math.sqrt(k),c*=k,f*=k,e.x+=c,e.y+=
f,b.x-=c,b.y-=f)}var Za,bb,ta,Ha,Pa,Wa,$a,ya;this.autoClear?this.clear():w.setTransform(1,0,0,-1,t,x);k.info.render.vertices=0;k.info.render.faces=0;h=n.projectScene(b,u,this.sortElements);(oa=b.lights.length>0)&&o(b);Za=0;for(bb=h.length;Za<bb;Za++){ta=h[Za];W.empty();if(ta instanceof THREE.RenderableParticle){H=ta;H.x*=t;H.y*=x;Ha=0;for(Pa=ta.materials.length;Ha<Pa;)ya=ta.materials[Ha++],ya.opacity!=0&&Xa(H,ta,ya,b)}else if(ta instanceof THREE.RenderableLine){if(H=ta.v1,J=ta.v2,H.positionScreen.x*=
t,H.positionScreen.y*=x,J.positionScreen.x*=t,J.positionScreen.y*=x,W.addPoint(H.positionScreen.x,H.positionScreen.y),W.addPoint(J.positionScreen.x,J.positionScreen.y),L.intersects(W)){Ha=0;for(Pa=ta.materials.length;Ha<Pa;)ya=ta.materials[Ha++],ya.opacity!=0&&y(H,J,ta,ya,b)}}else if(ta instanceof THREE.RenderableFace3){if(H=ta.v1,J=ta.v2,I=ta.v3,H.positionScreen.x*=t,H.positionScreen.y*=x,J.positionScreen.x*=t,J.positionScreen.y*=x,I.positionScreen.x*=t,I.positionScreen.y*=x,ta.overdraw&&(Oa(H.positionScreen,
J.positionScreen),Oa(J.positionScreen,I.positionScreen),Oa(I.positionScreen,H.positionScreen)),W.add3Points(H.positionScreen.x,H.positionScreen.y,J.positionScreen.x,J.positionScreen.y,I.positionScreen.x,I.positionScreen.y),L.intersects(W)){Ha=0;for(Pa=ta.meshMaterials.length;Ha<Pa;)if(ya=ta.meshMaterials[Ha++],ya instanceof THREE.MeshFaceMaterial){Wa=0;for($a=ta.faceMaterials.length;Wa<$a;)(ya=ta.faceMaterials[Wa++])&&ya.opacity!=0&&z(H,J,I,0,1,2,ta,ya,b)}else ya.opacity!=0&&z(H,J,I,0,1,2,ta,ya,b)}}else if(ta instanceof
THREE.RenderableFace4&&(H=ta.v1,J=ta.v2,I=ta.v3,X=ta.v4,H.positionScreen.x*=t,H.positionScreen.y*=x,J.positionScreen.x*=t,J.positionScreen.y*=x,I.positionScreen.x*=t,I.positionScreen.y*=x,X.positionScreen.x*=t,X.positionScreen.y*=x,E.positionScreen.copy(J.positionScreen),O.positionScreen.copy(X.positionScreen),ta.overdraw&&(Oa(H.positionScreen,J.positionScreen),Oa(J.positionScreen,X.positionScreen),Oa(X.positionScreen,H.positionScreen),Oa(I.positionScreen,E.positionScreen),Oa(I.positionScreen,O.positionScreen)),
W.addPoint(H.positionScreen.x,H.positionScreen.y),W.addPoint(J.positionScreen.x,J.positionScreen.y),W.addPoint(I.positionScreen.x,I.positionScreen.y),W.addPoint(X.positionScreen.x,X.positionScreen.y),L.intersects(W))){Ha=0;for(Pa=ta.meshMaterials.length;Ha<Pa;)if(ya=ta.meshMaterials[Ha++],ya instanceof THREE.MeshFaceMaterial){Wa=0;for($a=ta.faceMaterials.length;Wa<$a;)(ya=ta.faceMaterials[Wa++])&&ya.opacity!=0&&A(H,J,I,X,E,O,ta,ya,b)}else ya.opacity!=0&&A(H,J,I,X,E,O,ta,ya,b)}aa.addRectangle(W)}w.setTransform(1,
A
alteredq 已提交
179
0,0,1,0,0)}};
180
THREE.SVGRenderer=function(){function b(b,e,c){var f,k,h,m;f=0;for(k=b.lights.length;f<k;f++)h=b.lights[f],h instanceof THREE.DirectionalLight?(m=e.normalWorld.dot(h.position)*h.intensity,m>0&&(c.r+=h.color.r*m,c.g+=h.color.g*m,c.b+=h.color.b*m)):h instanceof THREE.PointLight&&(X.sub(h.position,e.centroidWorld),X.normalize(),m=e.normalWorld.dot(X)*h.intensity,m>0&&(c.r+=h.color.r*m,c.g+=h.color.g*m,c.b+=h.color.b*m))}function c(e,c,h,p,n,t){k.info.render.vertices+=3;k.info.render.faces++;P=f(U++);
181
P.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?G.copy(n.color):n instanceof THREE.MeshLambertMaterial?F?(N.r=R.r,N.g=R.g,N.b=R.b,b(t,p,N),G.r=Math.max(0,Math.min(n.color.r*N.r,1)),G.g=Math.max(0,Math.min(n.color.g*N.g,1)),G.b=Math.max(0,Math.min(n.color.b*N.b,1))):G.copy(n.color):n instanceof THREE.MeshDepthMaterial?(I=1-n.__2near/(n.__farPlusNear-
182
p.z*n.__farMinusNear),G.setRGB(I,I,I)):n instanceof THREE.MeshNormalMaterial&&G.setRGB(m(p.normalWorld.x),m(p.normalWorld.y),m(p.normalWorld.z));n.wireframe?P.setAttribute("style","fill: none; stroke: "+G.getContextStyle()+"; stroke-width: "+n.wireframeLinewidth+"; stroke-opacity: "+n.opacity+"; stroke-linecap: "+n.wireframeLinecap+"; stroke-linejoin: "+n.wireframeLinejoin):P.setAttribute("style","fill: "+G.getContextStyle()+"; fill-opacity: "+n.opacity);o.appendChild(P)}function e(e,c,h,p,n,t,w){k.info.render.vertices+=
183
4;k.info.render.faces++;P=f(U++);P.setAttribute("d","M "+e.positionScreen.x+" "+e.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+h.positionScreen.x+","+h.positionScreen.y+" L "+p.positionScreen.x+","+p.positionScreen.y+"z");t instanceof THREE.MeshBasicMaterial?G.copy(t.color):t instanceof THREE.MeshLambertMaterial?F?(N.r=R.r,N.g=R.g,N.b=R.b,b(w,n,N),G.r=Math.max(0,Math.min(t.color.r*N.r,1)),G.g=Math.max(0,Math.min(t.color.g*N.g,1)),G.b=Math.max(0,Math.min(t.color.b*N.b,1))):
184
G.copy(t.color):t instanceof THREE.MeshDepthMaterial?(I=1-t.__2near/(t.__farPlusNear-n.z*t.__farMinusNear),G.setRGB(I,I,I)):t instanceof THREE.MeshNormalMaterial&&G.setRGB(m(n.normalWorld.x),m(n.normalWorld.y),m(n.normalWorld.z));t.wireframe?P.setAttribute("style","fill: none; stroke: "+G.getContextStyle()+"; stroke-width: "+t.wireframeLinewidth+"; stroke-opacity: "+t.opacity+"; stroke-linecap: "+t.wireframeLinecap+"; stroke-linejoin: "+t.wireframeLinejoin):P.setAttribute("style","fill: "+G.getContextStyle()+
185
"; fill-opacity: "+t.opacity);o.appendChild(P)}function f(b){E[b]==null&&(E[b]=document.createElementNS("http://www.w3.org/2000/svg","path"),p==0&&E[b].setAttribute("shape-rendering","crispEdges"));return E[b]}function m(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}var k=this,h=null,n=new THREE.Projector,o=document.createElementNS("http://www.w3.org/2000/svg","svg"),u,v,t,x,w,y,A,z,D=new THREE.Rectangle,C=new THREE.Rectangle,F=!1,G=new THREE.Color(16777215),N=new THREE.Color(16777215),R=new THREE.Color(0),
186
H=new THREE.Color(0),J=new THREE.Color(0),I,X=new THREE.Vector3,E=[],O=[],P,U,V,p=1;this.domElement=o;this.sortElements=this.sortObjects=this.autoClear=!0;this.info={render:{vertices:0,faces:0}};this.setQuality=function(b){switch(b){case "high":p=1;break;case "low":p=0}};this.setSize=function(b,e){u=b;v=e;t=u/2;x=v/2;o.setAttribute("viewBox",-t+" "+-x+" "+u+" "+v);o.setAttribute("width",u);o.setAttribute("height",v);D.set(-t,-x,t,x)};this.clear=function(){for(;o.childNodes.length>0;)o.removeChild(o.childNodes[0])};
187 188
this.render=function(b,f){var m,u,v,G,N,E,I,T;this.autoClear&&this.clear();k.info.render.vertices=0;k.info.render.faces=0;h=n.projectScene(b,f,this.sortElements);V=U=0;if(F=b.lights.length>0){I=b.lights;R.setRGB(0,0,0);H.setRGB(0,0,0);J.setRGB(0,0,0);m=0;for(u=I.length;m<u;m++)v=I[m],G=v.color,v instanceof THREE.AmbientLight?(R.r+=G.r,R.g+=G.g,R.b+=G.b):v instanceof THREE.DirectionalLight?(H.r+=G.r,H.g+=G.g,H.b+=G.b):v instanceof THREE.PointLight&&(J.r+=G.r,J.g+=G.g,J.b+=G.b)}m=0;for(u=h.length;m<
u;m++)if(I=h[m],C.empty(),I instanceof THREE.RenderableParticle){w=I;w.x*=t;w.y*=-x;v=0;for(G=I.materials.length;v<G;)v++}else if(I instanceof THREE.RenderableLine){if(w=I.v1,y=I.v2,w.positionScreen.x*=t,w.positionScreen.y*=-x,y.positionScreen.x*=t,y.positionScreen.y*=-x,C.addPoint(w.positionScreen.x,w.positionScreen.y),C.addPoint(y.positionScreen.x,y.positionScreen.y),D.intersects(C)){v=0;for(G=I.materials.length;v<G;)if((T=I.materials[v++])&&T.opacity!=0){N=w;E=y;var Y=V++;O[Y]==null&&(O[Y]=document.createElementNS("http://www.w3.org/2000/svg",
189
"line"),p==0&&O[Y].setAttribute("shape-rendering","crispEdges"));P=O[Y];P.setAttribute("x1",N.positionScreen.x);P.setAttribute("y1",N.positionScreen.y);P.setAttribute("x2",E.positionScreen.x);P.setAttribute("y2",E.positionScreen.y);T instanceof THREE.LineBasicMaterial&&(P.setAttribute("style","fill: none; stroke: "+T.color.getContextStyle()+"; stroke-width: "+T.linewidth+"; stroke-opacity: "+T.opacity+"; stroke-linecap: "+T.linecap+"; stroke-linejoin: "+T.linejoin),o.appendChild(P))}}}else if(I instanceof
190 191 192
THREE.RenderableFace3){if(w=I.v1,y=I.v2,A=I.v3,w.positionScreen.x*=t,w.positionScreen.y*=-x,y.positionScreen.x*=t,y.positionScreen.y*=-x,A.positionScreen.x*=t,A.positionScreen.y*=-x,C.addPoint(w.positionScreen.x,w.positionScreen.y),C.addPoint(y.positionScreen.x,y.positionScreen.y),C.addPoint(A.positionScreen.x,A.positionScreen.y),D.intersects(C)){v=0;for(G=I.meshMaterials.length;v<G;)if(T=I.meshMaterials[v++],T instanceof THREE.MeshFaceMaterial){N=0;for(E=I.faceMaterials.length;N<E;)(T=I.faceMaterials[N++])&&
T.opacity!=0&&c(w,y,A,I,T,b)}else T&&T.opacity!=0&&c(w,y,A,I,T,b)}}else if(I instanceof THREE.RenderableFace4&&(w=I.v1,y=I.v2,A=I.v3,z=I.v4,w.positionScreen.x*=t,w.positionScreen.y*=-x,y.positionScreen.x*=t,y.positionScreen.y*=-x,A.positionScreen.x*=t,A.positionScreen.y*=-x,z.positionScreen.x*=t,z.positionScreen.y*=-x,C.addPoint(w.positionScreen.x,w.positionScreen.y),C.addPoint(y.positionScreen.x,y.positionScreen.y),C.addPoint(A.positionScreen.x,A.positionScreen.y),C.addPoint(z.positionScreen.x,z.positionScreen.y),
D.intersects(C))){v=0;for(G=I.meshMaterials.length;v<G;)if(T=I.meshMaterials[v++],T instanceof THREE.MeshFaceMaterial){N=0;for(E=I.faceMaterials.length;N<E;)(T=I.faceMaterials[N++])&&T.opacity!=0&&e(w,y,A,z,I,T,b)}else T&&T.opacity!=0&&e(w,y,A,z,I,T,b)}}};
193 194 195
THREE.ShaderChunk={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube envMap;\nuniform int combine;\n#endif",
envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( envMap, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refractionRatio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[ 0 ].xyz, objectMatrix[ 1 ].xyz, objectMatrix[ 2 ].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform vec4 offsetRepeat;\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",
A
alteredq 已提交
196 197 198 199
lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D lightMap;\n#endif",lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n#endif",
lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nfloat pointLightWeighting = max( dot( transformedNormal, lVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting * lDistance;\n}\n#endif\n}",
lights_phong_pars_vertex:"#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif",lights_phong_vertex:"#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif",
lights_pars_fragment:"uniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\n#if MAX_POINT_LIGHTS > 0\nvec3 pointDiffuse  = vec3( 0.0 );\nvec3 pointSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec3 pointVector = normalize( vPointLight[ i ].xyz );\nvec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );\nfloat pointDistance = vPointLight[ i ].w;\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse  += diffuse * pointLightColor[ i ] * pointDiffuseWeight * pointDistance;\npointSpecular += specular * pointLightColor[ i ] * pointSpecularWeight * pointDistance;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec3 dirDiffuse  = vec3( 0.0 );\nvec3 dirSpecular = vec3( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse  += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;\ndirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight;\n}\n#endif\nvec3 totalDiffuse = vec3( 0.0 );\nvec3 totalSpecular = vec3( 0.0 );\n#if MAX_DIR_LIGHTS > 0\ntotalDiffuse += dirDiffuse;\ntotalSpecular += dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalDiffuse += pointDiffuse;\ntotalSpecular += pointSpecular;\n#endif\ngl_FragColor.xyz = gl_FragColor.xyz * totalDiffuse + totalSpecular + ambientLightColor * ambient;",
200 201
color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\nvColor = color;\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\nuniform mat4 boneGlobalMatrices[ MAX_BONES ];\n#endif",skinning_vertex:"#ifdef USE_SKINNING\ngl_Position  = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;\ngl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;\ngl_Position  = projectionMatrix * viewMatrix * objectMatrix * gl_Position;\n#endif",
morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\nuniform float morphTargetInfluences[ 8 ];\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\nvec3 morphed = vec3( 0.0, 0.0, 0.0 );\nmorphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\nmorphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\nmorphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\nmorphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\nmorphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\nmorphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\nmorphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\nmorphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\nmorphed += position;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );\n#endif",
202
default_vertex:"#ifndef USE_MORPHTARGETS\n#ifndef USE_SKINNING\ngl_Position = projectionMatrix * mvPosition;\n#endif\n#endif",shadowmap_pars_fragment:"#ifdef USE_SHADOWMAP\nuniform sampler2D shadowMap[ MAX_SHADOWS ];\nuniform float shadowDarkness;\nuniform float shadowBias;\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nfloat unpackDepth( const in vec4 rgba_depth ) {\nconst vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\nfloat depth = dot( rgba_depth, bit_shift );\nreturn depth;\n}\n#endif",
A
alteredq 已提交
203
shadowmap_fragment:"#ifdef USE_SHADOWMAP\n#ifdef SHADOWMAP_SOFT\nconst float xPixelOffset = 1.0 / SHADOWMAP_WIDTH;\nconst float yPixelOffset = 1.0 / SHADOWMAP_HEIGHT;\n#endif\nvec4 shadowColor = vec4( 1.0 );\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\nvec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\nshadowCoord.z += shadowBias;\nif ( shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 ) {\n#ifdef SHADOWMAP_SOFT\nfloat shadow = 0.0;\nfor ( float y = -1.25; y <= 1.25; y += 1.25 )\nfor ( float x = -1.25; x <= 1.25; x += 1.25 ) {\nvec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadow += 1.0;\n}\nshadow /= 9.0;\nshadowColor = shadowColor * vec4( vec3( ( 1.0 - shadowDarkness * shadow ) ), 1.0 );\n#else\nvec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadowColor = shadowColor * vec4( vec3( shadowDarkness ), 1.0 );\n#endif\n}\n}\ngl_FragColor = gl_FragColor * shadowColor;\n#endif",
204
shadowmap_pars_vertex:"#ifdef USE_SHADOWMAP\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nuniform mat4 shadowMatrix[ MAX_SHADOWS ];\n#endif",shadowmap_vertex:"#ifdef USE_SHADOWMAP\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\nvShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( position, 1.0 );\n}\n#endif",alphatest_fragment:"#ifdef ALPHATEST\nif ( gl_FragColor.a < ALPHATEST ) discard;\n#endif"};
205
THREE.UniformsUtils={merge:function(b){var c,e,f,m={};for(c=0;c<b.length;c++)for(e in f=this.clone(b[c]),f)m[e]=f[e];return m},clone:function(b){var c,e,f,m={};for(c in b)for(e in m[c]={},b[c])f=b[c][e],m[c][e]=f instanceof THREE.Color||f instanceof THREE.Vector2||f instanceof THREE.Vector3||f instanceof THREE.Vector4||f instanceof THREE.Matrix4||f instanceof THREE.Texture?f.clone():f instanceof Array?f.slice():f;return m}};
A
alteredq 已提交
206 207
THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},offsetRepeat:{type:"v4",value:new THREE.Vector4(0,0,1,1)},lightMap:{type:"t",value:2,texture:null},envMap:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refractionRatio:{type:"f",value:0.98},combine:{type:"i",value:0},morphTargetInfluences:{type:"f",value:0}},fog:{fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",
value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{enableLighting:{type:"i",value:1},ambientLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightDistance:{type:"fv1",value:[]}},particle:{psColor:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},size:{type:"f",value:1},scale:{type:"f",
208
value:1},map:{type:"t",value:0,texture:null},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},shadowmap:{shadowMap:{type:"tv",value:3,texture:[]},shadowMatrix:{type:"m4v",value:[]},shadowBias:{type:"f",value:0.0039},shadowDarkness:{type:"f",value:0.2}}};
209
THREE.ShaderLib={sprite:{vertexShader:"uniform int useScreenCoordinates;\nuniform int affectedByDistance;\nuniform vec3 screenPosition;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform float rotation;\nuniform vec2 scale;\nuniform vec2 alignment;\nuniform vec2 uvOffset;\nuniform vec2 uvScale;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\nvUV = uvOffset + uv * uvScale;\nvec2 alignedPosition = position + alignment;\nvec2 rotatedPosition;\nrotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;\nrotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;\nvec4 finalPosition;\nif( useScreenCoordinates != 0 ) {\nfinalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );\n} else {\nfinalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\nfinalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );\n}\ngl_Position = finalPosition;\n}",fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform vec3 color;\nuniform sampler2D map;\nuniform float opacity;\nvarying vec2 vUV;\nvoid main() {\nvec4 texture = texture2D( map, vUV );\ngl_FragColor = vec4( color * texture.xyz, texture.a * opacity );\n}"},
M
Mr.doob 已提交
210 211 212 213 214 215 216 217
depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3},opacity:{type:"f",value:1}},vertexShader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform float mNear;\nuniform float mFar;\nuniform float opacity;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), opacity );\n}"},normal:{uniforms:{opacity:{type:"f",value:1}},
vertexShader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}",fragmentShader:"uniform float opacity;\nvarying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n}"},basic:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.shadowmap]),vertexShader:[THREE.ShaderChunk.map_pars_vertex,
THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,
THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,
THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},lambert:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap]),vertexShader:["varying vec3 vLightWeighting;",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_pars_vertex,
THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,"vec3 transformedNormal = normalize( normalMatrix * normal );",THREE.ShaderChunk.lights_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,
THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;\nvarying vec3 vLightWeighting;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,
"gl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );",THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},phong:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(328965)},specular:{type:"c",value:new THREE.Color(1118481)},shininess:{type:"f",
A
alteredq 已提交
218 219 220 221 222 223
value:30}}]),vertexShader:["varying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_phong_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,
THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = -mvPosition.xyz;\nvec3 transformedNormal = normalize( normalMatrix * normal );\nvNormal = transformedNormal;",THREE.ShaderChunk.lights_phong_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;\nuniform vec3 ambient;\nuniform vec3 specular;\nuniform float shininess;",
THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.lights_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( vec3 ( 1.0 ), opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.lights_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,
THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},particle_basic:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.particle,THREE.UniformsLib.shadowmap]),vertexShader:["uniform float size;\nuniform float scale;",THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {",THREE.ShaderChunk.color_vertex,"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n#ifdef USE_SIZEATTENUATION\ngl_PointSize = size * ( scale / length( mvPosition.xyz ) );\n#else\ngl_PointSize = size;\n#endif\ngl_Position = projectionMatrix * mvPosition;",
THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 psColor;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_particle_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( psColor, opacity );",THREE.ShaderChunk.map_particle_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.fog_fragment,
"}"].join("\n")},depthRGBA:{uniforms:{},vertexShader:[THREE.ShaderChunk.morphtarget_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,"}"].join("\n"),fragmentShader:"vec4 pack_depth( const in float depth ) {\nconst vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\nconst vec4 bit_mask  = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\nvec4 res = fract( depth * bit_shift );\nres -= res.xxyz * bit_mask;\nreturn res;\n}\nvoid main() {\ngl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );\n}"}};
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
THREE.WebGLRenderer=function(b){function c(b,e,c){var f,k,h,m=b.vertices,n=m.length,t=b.colors,o=t.length,w=b.__vertexArray,u=b.__colorArray,v=b.__sortArray,x=b.__dirtyVertices,L=b.__dirtyColors,y=b.__webglCustomAttributes,W,z;if(y)for(W in y)y[W].offset=0;if(c.sortParticles){ua.multiplySelf(c.matrixWorld);for(f=0;f<n;f++)k=m[f].position,Ba.copy(k),ua.multiplyVector3(Ba),v[f]=[Ba.z,f];v.sort(function(b,e){return e[0]-b[0]});for(f=0;f<n;f++)k=m[v[f][1]].position,h=f*3,w[h]=k.x,w[h+1]=k.y,w[h+2]=k.z;
for(f=0;f<o;f++)h=f*3,color=t[v[f][1]],u[h]=color.r,u[h+1]=color.g,u[h+2]=color.b;if(y)for(W in y){f=y[W];t=f.value.length;for(h=0;h<t;h++){index=v[h][1];o=f.offset;if(f.size===1){if(f.boundTo===void 0||f.boundTo==="vertices")f.array[o]=f.value[index]}else{if(f.boundTo===void 0||f.boundTo==="vertices")z=f.value[index];f.size===2?(f.array[o]=z.x,f.array[o+1]=z.y):f.size===3?f.type==="c"?(f.array[o]=z.r,f.array[o+1]=z.g,f.array[o+2]=z.b):(f.array[o]=z.x,f.array[o+1]=z.y,f.array[o+2]=z.z):(f.array[o]=
z.x,f.array[o+1]=z.y,f.array[o+2]=z.z,f.array[o+3]=z.w)}f.offset+=f.size}}}else{if(x)for(f=0;f<n;f++)k=m[f].position,h=f*3,w[h]=k.x,w[h+1]=k.y,w[h+2]=k.z;if(L)for(f=0;f<o;f++)color=t[f],h=f*3,u[h]=color.r,u[h+1]=color.g,u[h+2]=color.b;if(y)for(W in y)if(f=y[W],f.__original.needsUpdate){t=f.value.length;for(h=0;h<t;h++){o=f.offset;if(f.size===1){if(f.boundTo===void 0||f.boundTo==="vertices")f.array[o]=f.value[h]}else{if(f.boundTo===void 0||f.boundTo==="vertices")z=f.value[h];f.size===2?(f.array[o]=
z.x,f.array[o+1]=z.y):f.size===3?f.type==="c"?(f.array[o]=z.r,f.array[o+1]=z.g,f.array[o+2]=z.b):(f.array[o]=z.x,f.array[o+1]=z.y,f.array[o+2]=z.z):(f.array[o]=z.x,f.array[o+1]=z.y,f.array[o+2]=z.z,f.array[o+3]=z.w)}f.offset+=f.size}}}if(x||c.sortParticles)p.bindBuffer(p.ARRAY_BUFFER,b.__webglVertexBuffer),p.bufferData(p.ARRAY_BUFFER,w,e);if(L||c.sortParticles)p.bindBuffer(p.ARRAY_BUFFER,b.__webglColorBuffer),p.bufferData(p.ARRAY_BUFFER,u,e);if(y)for(W in y)if(f=y[W],f.__original.needsUpdate||c.sortParticles)p.bindBuffer(p.ARRAY_BUFFER,
f.buffer),p.bufferData(p.ARRAY_BUFFER,f.array,e)}function e(b,e,c,f,k){f.program||V.initMaterial(f,e,c,k);if(f.morphTargets&&!k.__webglMorphTargetInfluences){k.__webglMorphTargetInfluences=new Float32Array(V.maxMorphTargets);for(var h=0,m=V.maxMorphTargets;h<m;h++)k.__webglMorphTargetInfluences[h]=0}var n=!1,h=f.program,m=h.uniforms,o=f.uniforms;h!=S&&(p.useProgram(h),S=h,n=!0);if(f.id!=$)$=f.id,n=!0;if(n){p.uniformMatrix4fv(m.projectionMatrix,!1,Da);if(c&&f.fog)if(o.fogColor.value=c.color,c instanceof
THREE.Fog)o.fogNear.value=c.near,o.fogFar.value=c.far;else if(c instanceof THREE.FogExp2)o.fogDensity.value=c.density;if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f.lights){for(var t,w,u=0,v=0,x=0,y,z,W,aa=Fa,A=aa.directional.colors,D=aa.directional.positions,C=aa.point.colors,F=aa.point.positions,G=aa.point.distances,M=0,N=0,c=t=W=0,n=e.length;c<n;c++)if(t=e[c],w=t.color,y=t.position,z=t.intensity,W=t.distance,t instanceof THREE.AmbientLight)u+=w.r,v+=w.g,x+=w.b;
else if(t instanceof THREE.DirectionalLight)W=M*3,A[W]=w.r*z,A[W+1]=w.g*z,A[W+2]=w.b*z,D[W]=y.x,D[W+1]=y.y,D[W+2]=y.z,M+=1;else if(t instanceof THREE.SpotLight)W=M*3,A[W]=w.r*z,A[W+1]=w.g*z,A[W+2]=w.b*z,w=1/y.length(),D[W]=y.x*w,D[W+1]=y.y*w,D[W+2]=y.z*w,M+=1;else if(t instanceof THREE.PointLight)t=N*3,C[t]=w.r*z,C[t+1]=w.g*z,C[t+2]=w.b*z,F[t]=y.x,F[t+1]=y.y,F[t+2]=y.z,G[N]=W,N+=1;c=M*3;for(n=A.length;c<n;c++)A[c]=0;c=N*3;for(n=C.length;c<n;c++)C[c]=0;aa.point.length=N;aa.directional.length=M;aa.ambient[0]=
u;aa.ambient[1]=v;aa.ambient[2]=x;e=Fa;o.enableLighting.value=e.directional.length+e.point.length;o.ambientLightColor.value=e.ambient;o.directionalLightColor.value=e.directional.colors;o.directionalLightDirection.value=e.directional.positions;o.pointLightColor.value=e.point.colors;o.pointLightPosition.value=e.point.positions;o.pointLightDistance.value=e.point.distances}if(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial)o.diffuse.value=
f.color,o.opacity.value=f.opacity,(o.map.texture=f.map)&&o.offsetRepeat.value.set(f.map.offset.x,f.map.offset.y,f.map.repeat.x,f.map.repeat.y),o.lightMap.texture=f.lightMap,o.envMap.texture=f.envMap,o.reflectivity.value=f.reflectivity,o.refractionRatio.value=f.refractionRatio,o.combine.value=f.combine,o.useRefract.value=f.envMap&&f.envMap.mapping instanceof THREE.CubeRefractionMapping;if(f instanceof THREE.LineBasicMaterial)o.diffuse.value=f.color,o.opacity.value=f.opacity;else if(f instanceof THREE.ParticleBasicMaterial)o.psColor.value=
f.color,o.opacity.value=f.opacity,o.size.value=f.size,o.scale.value=L.height/2,o.map.texture=f.map;else if(f instanceof THREE.MeshPhongMaterial)o.ambient.value=f.ambient,o.specular.value=f.specular,o.shininess.value=f.shininess;else if(f instanceof THREE.MeshDepthMaterial)o.mNear.value=b.near,o.mFar.value=b.far,o.opacity.value=f.opacity;else if(f instanceof THREE.MeshNormalMaterial)o.opacity.value=f.opacity;if(k.receiveShadow&&!f._shadowPass&&o.shadowMatrix){for(e=0;e<na.length;e++)o.shadowMatrix.value[e]=
na[e],o.shadowMap.texture[e]=V.shadowMap[e];o.shadowDarkness.value=V.shadowMapDarkness;o.shadowBias.value=V.shadowMapBias}e=f.uniformsList;o=0;for(c=e.length;o<c;o++)if(v=h.uniforms[e[o][1]])if(u=e[o][0],x=u.type,n=u.value,x=="i")p.uniform1i(v,n);else if(x=="f")p.uniform1f(v,n);else if(x=="v2")p.uniform2f(v,n.x,n.y);else if(x=="v3")p.uniform3f(v,n.x,n.y,n.z);else if(x=="v4")p.uniform4f(v,n.x,n.y,n.z,n.w);else if(x=="c")p.uniform3f(v,n.r,n.g,n.b);else if(x=="fv1")p.uniform1fv(v,n);else if(x=="fv")p.uniform3fv(v,
n);else if(x=="v3v"){if(!u._array)u._array=new Float32Array(3*n.length);x=0;for(y=n.length;x<y;x++)aa=x*3,u._array[aa]=n[x].x,u._array[aa+1]=n[x].y,u._array[aa+2]=n[x].z;p.uniform3fv(v,u._array)}else if(x=="m4"){if(!u._array)u._array=new Float32Array(16);n.flattenToArray(u._array);p.uniformMatrix4fv(v,!1,u._array)}else if(x=="m4v"){if(!u._array)u._array=new Float32Array(16*n.length);x=0;for(y=n.length;x<y;x++)n[x].flattenToArrayOffset(u._array,x*16);p.uniformMatrix4fv(v,!1,u._array)}else if(x=="t"){if(p.uniform1i(v,
n),v=u.texture)if(v.image instanceof Array&&v.image.length==6){if(u=v,u.image.length==6)if(u.needsUpdate){if(!u.image.__webglTextureCube)u.image.__webglTextureCube=p.createTexture();p.activeTexture(p.TEXTURE0+n);p.bindTexture(p.TEXTURE_CUBE_MAP,u.image.__webglTextureCube);for(n=0;n<6;n++)p.texImage2D(p.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,p.RGBA,p.RGBA,p.UNSIGNED_BYTE,u.image[n]);J(p.TEXTURE_CUBE_MAP,u,u.image[0]);u.needsUpdate=!1}else p.activeTexture(p.TEXTURE0+n),p.bindTexture(p.TEXTURE_CUBE_MAP,u.image.__webglTextureCube)}else v instanceof
THREE.WebGLRenderTargetCube?(u=v,p.activeTexture(p.TEXTURE0+n),p.bindTexture(p.TEXTURE_CUBE_MAP,u.__webglTexture)):I(v,n)}else if(x=="tv"){if(!u._array){u._array=[];x=0;for(y=u.texture.length;x<y;x++)u._array[x]=n+x}p.uniform1iv(v,u._array);x=0;for(y=u.texture.length;x<y;x++)(v=u.texture[x])&&I(v,u._array[x])}(f instanceof THREE.ShaderMaterial||f instanceof THREE.MeshPhongMaterial||f.envMap)&&m.cameraPosition!==null&&p.uniform3f(m.cameraPosition,b.position.x,b.position.y,b.position.z);(f instanceof
THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.ShaderMaterial||f.skinning)&&m.viewMatrix!==null&&p.uniformMatrix4fv(m.viewMatrix,!1,za);f.skinning&&(p.uniformMatrix4fv(m.cameraInverseMatrix,!1,za),p.uniformMatrix4fv(m.boneGlobalMatrices,!1,k.boneMatrices))}p.uniformMatrix4fv(m.modelViewMatrix,!1,k._modelViewMatrixArray);m.normalMatrix&&p.uniformMatrix3fv(m.normalMatrix,!1,k._normalMatrixArray);(f instanceof THREE.ShaderMaterial||f.envMap||f.skinning||k.receiveShadow)&&
m.objectMatrix!==null&&p.uniformMatrix4fv(m.objectMatrix,!1,k._objectMatrixArray);return h}function f(b,c,f,k,h,m){if(k.opacity!=0){var n,f=e(b,c,f,k,m),b=f.attributes,c=!1,f=h.id*16777215+f.id;f!=ia&&(ia=f,c=!0);if(!k.morphTargets&&b.position>=0)c&&(p.bindBuffer(p.ARRAY_BUFFER,h.__webglVertexBuffer),p.vertexAttribPointer(b.position,3,p.FLOAT,!1,0,0));else if(m.morphTargetBase){f=k.program.attributes;m.morphTargetBase!==-1?(p.bindBuffer(p.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[m.morphTargetBase]),
p.vertexAttribPointer(f.position,3,p.FLOAT,!1,0,0)):f.position>=0&&(p.bindBuffer(p.ARRAY_BUFFER,h.__webglVertexBuffer),p.vertexAttribPointer(f.position,3,p.FLOAT,!1,0,0));if(m.morphTargetForcedOrder.length)for(var o=0,t=m.morphTargetForcedOrder,u=m.morphTargetInfluences;o<k.numSupportedMorphTargets&&o<t.length;)p.bindBuffer(p.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[t[o]]),p.vertexAttribPointer(f["morphTarget"+o],3,p.FLOAT,!1,0,0),m.__webglMorphTargetInfluences[o]=u[t[o]],o++;else{var t=[],w=-1,
v=0,u=m.morphTargetInfluences,x,y=u.length,o=0;for(m.morphTargetBase!==-1&&(t[m.morphTargetBase]=!0);o<k.numSupportedMorphTargets;){for(x=0;x<y;x++)!t[x]&&u[x]>w&&(v=x,w=u[v]);p.bindBuffer(p.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[v]);p.vertexAttribPointer(f["morphTarget"+o],3,p.FLOAT,!1,0,0);m.__webglMorphTargetInfluences[o]=w;t[v]=1;w=-1;o++}}k.program.uniforms.morphTargetInfluences!==null&&p.uniform1fv(k.program.uniforms.morphTargetInfluences,m.__webglMorphTargetInfluences)}if(c){if(h.__webglCustomAttributes)for(n in h.__webglCustomAttributes)b[n]>=
0&&(f=h.__webglCustomAttributes[n],p.bindBuffer(p.ARRAY_BUFFER,f.buffer),p.vertexAttribPointer(b[n],f.size,p.FLOAT,!1,0,0));b.color>=0&&(p.bindBuffer(p.ARRAY_BUFFER,h.__webglColorBuffer),p.vertexAttribPointer(b.color,3,p.FLOAT,!1,0,0));b.normal>=0&&(p.bindBuffer(p.ARRAY_BUFFER,h.__webglNormalBuffer),p.vertexAttribPointer(b.normal,3,p.FLOAT,!1,0,0));b.tangent>=0&&(p.bindBuffer(p.ARRAY_BUFFER,h.__webglTangentBuffer),p.vertexAttribPointer(b.tangent,4,p.FLOAT,!1,0,0));b.uv>=0&&(h.__webglUVBuffer?(p.bindBuffer(p.ARRAY_BUFFER,
h.__webglUVBuffer),p.vertexAttribPointer(b.uv,2,p.FLOAT,!1,0,0),p.enableVertexAttribArray(b.uv)):p.disableVertexAttribArray(b.uv));b.uv2>=0&&(h.__webglUV2Buffer?(p.bindBuffer(p.ARRAY_BUFFER,h.__webglUV2Buffer),p.vertexAttribPointer(b.uv2,2,p.FLOAT,!1,0,0),p.enableVertexAttribArray(b.uv2)):p.disableVertexAttribArray(b.uv2));k.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0&&(p.bindBuffer(p.ARRAY_BUFFER,h.__webglSkinVertexABuffer),p.vertexAttribPointer(b.skinVertexA,4,
p.FLOAT,!1,0,0),p.bindBuffer(p.ARRAY_BUFFER,h.__webglSkinVertexBBuffer),p.vertexAttribPointer(b.skinVertexB,4,p.FLOAT,!1,0,0),p.bindBuffer(p.ARRAY_BUFFER,h.__webglSkinIndicesBuffer),p.vertexAttribPointer(b.skinIndex,4,p.FLOAT,!1,0,0),p.bindBuffer(p.ARRAY_BUFFER,h.__webglSkinWeightsBuffer),p.vertexAttribPointer(b.skinWeight,4,p.FLOAT,!1,0,0))}m instanceof THREE.Mesh?(k.wireframe?(p.lineWidth(k.wireframeLinewidth),c&&p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,h.__webglLineBuffer),p.drawElements(p.LINES,h.__webglLineCount,
p.UNSIGNED_SHORT,0)):(c&&p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,h.__webglFaceBuffer),p.drawElements(p.TRIANGLES,h.__webglFaceCount,p.UNSIGNED_SHORT,0)),V.info.render.calls++,V.info.render.vertices+=h.__webglFaceCount,V.info.render.faces+=h.__webglFaceCount/3):m instanceof THREE.Line?(m=m.type==THREE.LineStrip?p.LINE_STRIP:p.LINES,p.lineWidth(k.linewidth),p.drawArrays(m,0,h.__webglLineCount),V.info.render.calls++):m instanceof THREE.ParticleSystem?(p.drawArrays(p.POINTS,0,h.__webglParticleCount),V.info.render.calls++):
m instanceof THREE.Ribbon&&(p.drawArrays(p.TRIANGLE_STRIP,0,h.__webglVertexCount),V.info.render.calls++)}}function m(b,e,c){if(!b.__webglVertexBuffer)b.__webglVertexBuffer=p.createBuffer();if(!b.__webglNormalBuffer)b.__webglNormalBuffer=p.createBuffer();b.hasPos&&(p.bindBuffer(p.ARRAY_BUFFER,b.__webglVertexBuffer),p.bufferData(p.ARRAY_BUFFER,b.positionArray,p.DYNAMIC_DRAW),p.enableVertexAttribArray(e.attributes.position),p.vertexAttribPointer(e.attributes.position,3,p.FLOAT,!1,0,0));if(b.hasNormal){p.bindBuffer(p.ARRAY_BUFFER,
b.__webglNormalBuffer);if(c==THREE.FlatShading){var f,h,k,m,n,o,t,u,w,v,x=b.count*3;for(v=0;v<x;v+=9)c=b.normalArray,f=c[v],h=c[v+1],k=c[v+2],m=c[v+3],o=c[v+4],u=c[v+5],n=c[v+6],t=c[v+7],w=c[v+8],f=(f+m+n)/3,h=(h+o+t)/3,k=(k+u+w)/3,c[v]=f,c[v+1]=h,c[v+2]=k,c[v+3]=f,c[v+4]=h,c[v+5]=k,c[v+6]=f,c[v+7]=h,c[v+8]=k}p.bufferData(p.ARRAY_BUFFER,b.normalArray,p.DYNAMIC_DRAW);p.enableVertexAttribArray(e.attributes.normal);p.vertexAttribPointer(e.attributes.normal,3,p.FLOAT,!1,0,0)}p.drawArrays(p.TRIANGLES,
0,b.count);b.count=0}function k(b){if(ma!=b.doubleSided)b.doubleSided?p.disable(p.CULL_FACE):p.enable(p.CULL_FACE),ma=b.doubleSided;if(fa!=b.flipSided)b.flipSided?p.frontFace(p.CW):p.frontFace(p.CCW),fa=b.flipSided}function h(b){T!=b&&(b?p.enable(p.DEPTH_TEST):p.disable(p.DEPTH_TEST),T=b)}function n(b){Y!=b&&(p.depthMask(b),Y=b)}function o(b,e,c){ga!=b&&(b?p.enable(p.POLYGON_OFFSET_FILL):p.disable(p.POLYGON_OFFSET_FILL),ga=b);if(b&&(ja!=e||sa!=c))p.polygonOffset(e,c),ja=e,sa=c}function u(b){wa[0].set(b.n41-
b.n11,b.n42-b.n12,b.n43-b.n13,b.n44-b.n14);wa[1].set(b.n41+b.n11,b.n42+b.n12,b.n43+b.n13,b.n44+b.n14);wa[2].set(b.n41+b.n21,b.n42+b.n22,b.n43+b.n23,b.n44+b.n24);wa[3].set(b.n41-b.n21,b.n42-b.n22,b.n43-b.n23,b.n44-b.n24);wa[4].set(b.n41-b.n31,b.n42-b.n32,b.n43-b.n33,b.n44-b.n34);wa[5].set(b.n41+b.n31,b.n42+b.n32,b.n43+b.n33,b.n44+b.n34);for(var e,b=0;b<6;b++)e=wa[b],e.divideScalar(Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z))}function v(b){for(var e=b.matrixWorld,c=-b.geometry.boundingSphere.radius*Math.max(b.scale.x,
Math.max(b.scale.y,b.scale.z)),f=0;f<6;f++)if(b=wa[f].x*e.n14+wa[f].y*e.n24+wa[f].z*e.n34+wa[f].w,b<=c)return!1;return!0}function t(b,e){b.list[b.count]=e;b.count+=1}function x(b){var e,c,f=b.object,h=b.opaque,k=b.transparent;k.count=0;b=h.count=0;for(e=f.materials.length;b<e;b++)c=f.materials[b],c.transparent?t(k,c):t(h,c)}function w(b){var e,c,f,h,k=b.object,m=b.buffer,n=b.opaque,p=b.transparent;p.count=0;b=n.count=0;for(f=k.materials.length;b<f;b++)if(e=k.materials[b],e instanceof THREE.MeshFaceMaterial){e=
0;for(c=m.materials.length;e<c;e++)(h=m.materials[e])&&(h.transparent?t(p,h):t(n,h))}else(h=e)&&(h.transparent?t(p,h):t(n,h))}function y(b,e){return e.z-b.z}function A(b){var c,n,o,t=0,w,x,y,L,z=b.lights;va||(va=new THREE.Camera(V.shadowCameraFov,V.shadowMapWidth/V.shadowMapHeight,V.shadowCameraNear,V.shadowCameraFar));c=0;for(n=z.length;c<n;c++)if(o=z[c],o instanceof THREE.SpotLight&&o.castShadow){$=-1;V.shadowMap[t]||(V.shadowMap[t]=new THREE.WebGLRenderTarget(V.shadowMapWidth,V.shadowMapHeight,
{minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBAFormat}));na[t]||(na[t]=new THREE.Matrix4);w=V.shadowMap[t];x=na[t];va.position.copy(o.position);va.target.position.copy(o.target.position);va.update(void 0,!0);b.update(void 0,!1,va);x.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);x.multiplySelf(va.projectionMatrix);x.multiplySelf(va.matrixWorldInverse);va.matrixWorldInverse.flattenToArray(za);va.projectionMatrix.flattenToArray(Da);ua.multiply(va.projectionMatrix,va.matrixWorldInverse);
u(ua);V.initWebGLObjects(b);X(w);p.clearColor(1,1,1,1);V.clear();p.clearColor(ha.r,ha.g,ha.b,ra);x=b.__webglObjects.length;o=b.__webglObjectsImmediate.length;for(w=0;w<x;w++)y=b.__webglObjects[w],L=y.object,L.visible&&L.castShadow?!(L instanceof THREE.Mesh)||!L.frustumCulled||v(L)?(L.matrixWorld.flattenToArray(L._objectMatrixArray),D(L,va,!1),y.render=!0):y.render=!1:y.render=!1;h(!0);H(THREE.NormalBlending);for(w=0;w<x;w++)if(y=b.__webglObjects[w],y.render)L=y.object,buffer=y.buffer,k(L),y=L.customDepthMaterial?
L.customDepthMaterial:L.geometry.morphTargets.length?Ka:xa,f(va,z,null,y,buffer,L);for(w=0;w<o;w++)y=b.__webglObjectsImmediate[w],L=y.object,L.visible&&L.castShadow&&(L.matrixAutoUpdate&&L.matrixWorld.flattenToArray(L._objectMatrixArray),D(L,va,!1),k(L),program=e(va,z,null,xa,L),L.render(function(b){m(b,program,xa.shading)}));t++}}function z(b,e){var c,f,h;c=Z.attributes;var k=Z.uniforms,m=qa/pa,n,o=[],t=pa*0.5,w=qa*0.5,u=!0;p.useProgram(Z.program);S=Z.program;ia=T=da=-1;Ja||(p.enableVertexAttribArray(Z.attributes.position),
p.enableVertexAttribArray(Z.attributes.uv),Ja=!0);p.disable(p.CULL_FACE);p.enable(p.BLEND);p.depthMask(!0);p.bindBuffer(p.ARRAY_BUFFER,Z.vertexBuffer);p.vertexAttribPointer(c.position,2,p.FLOAT,!1,16,0);p.vertexAttribPointer(c.uv,2,p.FLOAT,!1,16,8);p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,Z.elementBuffer);p.uniformMatrix4fv(k.projectionMatrix,!1,Da);p.activeTexture(p.TEXTURE0);p.uniform1i(k.map,0);c=0;for(f=b.__webglSprites.length;c<f;c++)if(h=b.__webglSprites[c],h.visible&&h.opacity!=0)h.useScreenCoordinates?
h.z=-h.position.z:(h._modelViewMatrix.multiplyToArray(e.matrixWorldInverse,h.matrixWorld,h._modelViewMatrixArray),h.z=-h._modelViewMatrix.n34);b.__webglSprites.sort(y);c=0;for(f=b.__webglSprites.length;c<f;c++)h=b.__webglSprites[c],h.visible&&h.opacity!=0&&h.map&&h.map.image&&h.map.image.width&&(h.useScreenCoordinates?(p.uniform1i(k.useScreenCoordinates,1),p.uniform3f(k.screenPosition,(h.position.x-t)/t,(w-h.position.y)/w,Math.max(0,Math.min(1,h.position.z)))):(p.uniform1i(k.useScreenCoordinates,
0),p.uniform1i(k.affectedByDistance,h.affectedByDistance?1:0),p.uniformMatrix4fv(k.modelViewMatrix,!1,h._modelViewMatrixArray)),n=h.map.image.width/(h.scaleByViewport?qa:1),o[0]=n*m*h.scale.x,o[1]=n*h.scale.y,p.uniform2f(k.uvScale,h.uvScale.x,h.uvScale.y),p.uniform2f(k.uvOffset,h.uvOffset.x,h.uvOffset.y),p.uniform2f(k.alignment,h.alignment.x,h.alignment.y),p.uniform1f(k.opacity,h.opacity),p.uniform3f(k.color,h.color.r,h.color.g,h.color.b),p.uniform1f(k.rotation,h.rotation),p.uniform2fv(k.scale,o),
258 259
h.mergeWith3D&&!u?(p.enable(p.DEPTH_TEST),u=!0):!h.mergeWith3D&&u&&(p.disable(p.DEPTH_TEST),u=!1),H(h.blending),I(h.map,0),p.drawElements(p.TRIANGLES,6,p.UNSIGNED_SHORT,0));p.enable(p.CULL_FACE);p.enable(p.DEPTH_TEST);p.depthMask(Y)}function D(b,e,c){b._modelViewMatrix.multiplyToArray(e.matrixWorldInverse,b.matrixWorld,b._modelViewMatrixArray);c&&THREE.Matrix4.makeInvert3x3(b._modelViewMatrix).transposeIntoArray(b._normalMatrixArray)}function C(b){var e,c,f,h;h=b.__materials;b=0;for(c=h.length;b<
c;b++)if(f=h[b],f.attributes)for(e in f.attributes)if(f.attributes[e].needsUpdate)return!0;return!1}function F(b){var e,c,f,h;h=b.__materials;b=0;for(c=h.length;b<c;b++)if(f=h[b],f.attributes)for(e in f.attributes)f.attributes[e].needsUpdate=!1}function G(b,e){var c;for(c=b.length-1;c>=0;c--)b[c].object==e&&b.splice(c,1)}function N(b){function e(b){var h=[];c=0;for(f=b.length;c<f;c++)b[c]==void 0?h.push("undefined"):h.push(b[c].id);return h.join("_")}var c,f,h,k,m,n,p,o,t={},w=b.morphTargets!==void 0?
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
b.morphTargets.length:0;b.geometryGroups={};h=0;for(k=b.faces.length;h<k;h++)m=b.faces[h],n=m.materials,p=e(n),t[p]==void 0&&(t[p]={hash:p,counter:0}),o=t[p].hash+"_"+t[p].counter,b.geometryGroups[o]==void 0&&(b.geometryGroups[o]={faces:[],materials:n,vertices:0,numMorphTargets:w}),m=m instanceof THREE.Face3?3:4,b.geometryGroups[o].vertices+m>65535&&(t[p].counter+=1,o=t[p].hash+"_"+t[p].counter,b.geometryGroups[o]==void 0&&(b.geometryGroups[o]={faces:[],materials:n,vertices:0,numMorphTargets:w})),
b.geometryGroups[o].faces.push(h),b.geometryGroups[o].vertices+=m;b.geometryGroupsList=[];for(var u in b.geometryGroups)b.geometryGroups[u].id=ca++,b.geometryGroupsList.push(b.geometryGroups[u])}function R(b,e,c){b.push({buffer:e,object:c,opaque:{list:[],count:0},transparent:{list:[],count:0}})}function H(b){if(b!=da){switch(b){case THREE.AdditiveBlending:p.blendEquation(p.FUNC_ADD);p.blendFunc(p.SRC_ALPHA,p.ONE);break;case THREE.SubtractiveBlending:p.blendEquation(p.FUNC_ADD);p.blendFunc(p.ZERO,
p.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:p.blendEquation(p.FUNC_ADD);p.blendFunc(p.ZERO,p.SRC_COLOR);break;default:p.blendEquationSeparate(p.FUNC_ADD,p.FUNC_ADD),p.blendFuncSeparate(p.SRC_ALPHA,p.ONE_MINUS_SRC_ALPHA,p.ONE,p.ONE_MINUS_SRC_ALPHA)}da=b}}function J(b,e,c){(c.width&c.width-1)==0&&(c.height&c.height-1)==0?(p.texParameteri(b,p.TEXTURE_WRAP_S,U(e.wrapS)),p.texParameteri(b,p.TEXTURE_WRAP_T,U(e.wrapT)),p.texParameteri(b,p.TEXTURE_MAG_FILTER,U(e.magFilter)),p.texParameteri(b,
p.TEXTURE_MIN_FILTER,U(e.minFilter)),p.generateMipmap(b)):(p.texParameteri(b,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(b,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE),p.texParameteri(b,p.TEXTURE_MAG_FILTER,P(e.magFilter)),p.texParameteri(b,p.TEXTURE_MIN_FILTER,P(e.minFilter)))}function I(b,e){if(b.needsUpdate){if(!b.__webglInit)b.__webglInit=!0,b.__webglTexture=p.createTexture(),V.info.memory.textures++;p.activeTexture(p.TEXTURE0+e);p.bindTexture(p.TEXTURE_2D,b.__webglTexture);b instanceof THREE.DataTexture?
p.texImage2D(p.TEXTURE_2D,0,U(b.format),b.image.width,b.image.height,0,U(b.format),p.UNSIGNED_BYTE,b.image.data):p.texImage2D(p.TEXTURE_2D,0,p.RGBA,p.RGBA,p.UNSIGNED_BYTE,b.image);J(p.TEXTURE_2D,b,b.image);b.needsUpdate=!1}else p.activeTexture(p.TEXTURE0+e),p.bindTexture(p.TEXTURE_2D,b.__webglTexture)}function X(b){var e=b instanceof THREE.WebGLRenderTargetCube;if(b&&!b.__webglFramebuffer){if(b.depthBuffer===void 0)b.depthBuffer=!0;if(b.stencilBuffer===void 0)b.stencilBuffer=!0;b.__webglRenderbuffer=
p.createRenderbuffer();b.__webglTexture=p.createTexture();if(e){p.bindTexture(p.TEXTURE_CUBE_MAP,b.__webglTexture);J(p.TEXTURE_CUBE_MAP,b,b);b.__webglFramebuffer=[];for(var c=0;c<6;c++)b.__webglFramebuffer[c]=p.createFramebuffer(),p.texImage2D(p.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,U(b.format),b.width,b.height,0,U(b.format),U(b.type),null)}else b.__webglFramebuffer=p.createFramebuffer(),p.bindTexture(p.TEXTURE_2D,b.__webglTexture),J(p.TEXTURE_2D,b,b),p.texImage2D(p.TEXTURE_2D,0,U(b.format),b.width,b.height,
0,U(b.format),U(b.type),null);p.bindRenderbuffer(p.RENDERBUFFER,b.__webglRenderbuffer);if(e)for(c=0;c<6;++c)p.bindFramebuffer(p.FRAMEBUFFER,b.__webglFramebuffer[c]),p.framebufferTexture2D(p.FRAMEBUFFER,p.COLOR_ATTACHMENT0,p.TEXTURE_CUBE_MAP_POSITIVE_X+c,b.__webglTexture,0);else p.bindFramebuffer(p.FRAMEBUFFER,b.__webglFramebuffer),p.framebufferTexture2D(p.FRAMEBUFFER,p.COLOR_ATTACHMENT0,p.TEXTURE_2D,b.__webglTexture,0);b.depthBuffer&&!b.stencilBuffer?(p.renderbufferStorage(p.RENDERBUFFER,p.DEPTH_COMPONENT16,
b.width,b.height),p.framebufferRenderbuffer(p.FRAMEBUFFER,p.DEPTH_ATTACHMENT,p.RENDERBUFFER,b.__webglRenderbuffer)):b.depthBuffer&&b.stencilBuffer?(p.renderbufferStorage(p.RENDERBUFFER,p.DEPTH_STENCIL,b.width,b.height),p.framebufferRenderbuffer(p.FRAMEBUFFER,p.DEPTH_STENCIL_ATTACHMENT,p.RENDERBUFFER,b.__webglRenderbuffer)):p.renderbufferStorage(p.RENDERBUFFER,p.RGBA4,b.width,b.height);e?p.bindTexture(p.TEXTURE_CUBE_MAP,null):p.bindTexture(p.TEXTURE_2D,null);p.bindRenderbuffer(p.RENDERBUFFER,null);
p.bindFramebuffer(p.FRAMEBUFFER,null)}var f,h;b?(e=e?b.__webglFramebuffer[b.activeCubeFace]:b.__webglFramebuffer,c=b.width,b=b.height,h=f=0):(e=null,c=pa,b=qa,f=M,h=la);e!=ka&&(p.bindFramebuffer(p.FRAMEBUFFER,e),p.viewport(f,h,c,b),ka=e)}function E(b){b instanceof THREE.WebGLRenderTargetCube?(p.bindTexture(p.TEXTURE_CUBE_MAP,b.__webglTexture),p.generateMipmap(p.TEXTURE_CUBE_MAP),p.bindTexture(p.TEXTURE_CUBE_MAP,null)):(p.bindTexture(p.TEXTURE_2D,b.__webglTexture),p.generateMipmap(p.TEXTURE_2D),p.bindTexture(p.TEXTURE_2D,
null))}function O(b,e){var c;b=="fragment"?c=p.createShader(p.FRAGMENT_SHADER):b=="vertex"&&(c=p.createShader(p.VERTEX_SHADER));p.shaderSource(c,e);p.compileShader(c);if(!p.getShaderParameter(c,p.COMPILE_STATUS))return console.error(p.getShaderInfoLog(c)),console.error(e),null;return c}function P(b){switch(b){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return p.NEAREST;default:return p.LINEAR}}function U(b){switch(b){case THREE.RepeatWrapping:return p.REPEAT;
case THREE.ClampToEdgeWrapping:return p.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return p.MIRRORED_REPEAT;case THREE.NearestFilter:return p.NEAREST;case THREE.NearestMipMapNearestFilter:return p.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return p.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return p.LINEAR;case THREE.LinearMipMapNearestFilter:return p.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return p.LINEAR_MIPMAP_LINEAR;case THREE.ByteType:return p.BYTE;
case THREE.UnsignedByteType:return p.UNSIGNED_BYTE;case THREE.ShortType:return p.SHORT;case THREE.UnsignedShortType:return p.UNSIGNED_SHORT;case THREE.IntType:return p.INT;case THREE.UnsignedShortType:return p.UNSIGNED_INT;case THREE.FloatType:return p.FLOAT;case THREE.AlphaFormat:return p.ALPHA;case THREE.RGBFormat:return p.RGB;case THREE.RGBAFormat:return p.RGBA;case THREE.LuminanceFormat:return p.LUMINANCE;case THREE.LuminanceAlphaFormat:return p.LUMINANCE_ALPHA}return 0}var V=this,p,ea=[],S=null,
ka=null,$=-1,ia=null,ca=0,ma=null,fa=null,da=null,T=null,Y=null,ga=null,ja=null,sa=null,M=0,la=0,pa=0,qa=0,wa=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],ua=new THREE.Matrix4,Da=new Float32Array(16),za=new Float32Array(16),Ba=new THREE.Vector4,Fa={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]}},b=b||{},L=b.canvas!==void 0?b.canvas:document.createElement("canvas"),aa=
b.stencil!==void 0?b.stencil:!0,W=b.preserveDrawingBuffer!==void 0?b.preserveDrawingBuffer:!1,oa=b.antialias!==void 0?b.antialias:!1,ha=b.clearColor!==void 0?new THREE.Color(b.clearColor):new THREE.Color(0),ra=b.clearAlpha!==void 0?b.clearAlpha:0,Ca=b.maxLights!==void 0?b.maxLights:4;this.info={memory:{programs:0,geometries:0,textures:0},render:{calls:0,vertices:0,faces:0}};this.maxMorphTargets=8;this.domElement=L;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 va,na=[],b=THREE.ShaderLib.depthRGBA,Ia=THREE.UniformsUtils.clone(b.uniforms),xa=new THREE.ShaderMaterial({fragmentShader:b.fragmentShader,vertexShader:b.vertexShader,uniforms:Ia}),Ka=new THREE.ShaderMaterial({fragmentShader:b.fragmentShader,vertexShader:b.vertexShader,uniforms:Ia,morphTargets:!0});xa._shadowPass=
!0;Ka._shadowPass=!0;try{if(!(p=L.getContext("experimental-webgl",{antialias:oa,stencil:aa,preserveDrawingBuffer:W})))throw"Error creating WebGL context.";console.log(navigator.userAgent+" | "+p.getParameter(p.VERSION)+" | "+p.getParameter(p.VENDOR)+" | "+p.getParameter(p.RENDERER)+" | "+p.getParameter(p.SHADING_LANGUAGE_VERSION))}catch(Aa){console.error(Aa)}p.clearColor(0,0,0,1);p.clearDepth(1);p.clearStencil(0);p.enable(p.DEPTH_TEST);p.depthFunc(p.LEQUAL);p.frontFace(p.CCW);p.cullFace(p.BACK);p.enable(p.CULL_FACE);
p.enable(p.BLEND);p.blendEquation(p.FUNC_ADD);p.blendFunc(p.SRC_ALPHA,p.ONE_MINUS_SRC_ALPHA);p.clearColor(ha.r,ha.g,ha.b,ra);this.context=p;var Ga=p.getParameter(p.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0,Z={};Z.vertices=new Float32Array(16);Z.faces=new Uint16Array(6);aa=0;Z.vertices[aa++]=-1;Z.vertices[aa++]=-1;Z.vertices[aa++]=0;Z.vertices[aa++]=1;Z.vertices[aa++]=1;Z.vertices[aa++]=-1;Z.vertices[aa++]=1;Z.vertices[aa++]=1;Z.vertices[aa++]=1;Z.vertices[aa++]=1;Z.vertices[aa++]=1;Z.vertices[aa++]=0;Z.vertices[aa++]=
-1;Z.vertices[aa++]=1;Z.vertices[aa++]=0;aa=Z.vertices[aa++]=0;Z.faces[aa++]=0;Z.faces[aa++]=1;Z.faces[aa++]=2;Z.faces[aa++]=0;Z.faces[aa++]=2;Z.faces[aa++]=3;Z.vertexBuffer=p.createBuffer();Z.elementBuffer=p.createBuffer();p.bindBuffer(p.ARRAY_BUFFER,Z.vertexBuffer);p.bufferData(p.ARRAY_BUFFER,Z.vertices,p.STATIC_DRAW);p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,Z.elementBuffer);p.bufferData(p.ELEMENT_ARRAY_BUFFER,Z.faces,p.STATIC_DRAW);Z.program=p.createProgram();p.attachShader(Z.program,O("fragment",THREE.ShaderLib.sprite.fragmentShader));
p.attachShader(Z.program,O("vertex",THREE.ShaderLib.sprite.vertexShader));p.linkProgram(Z.program);Z.attributes={};Z.uniforms={};Z.attributes.position=p.getAttribLocation(Z.program,"position");Z.attributes.uv=p.getAttribLocation(Z.program,"uv");Z.uniforms.uvOffset=p.getUniformLocation(Z.program,"uvOffset");Z.uniforms.uvScale=p.getUniformLocation(Z.program,"uvScale");Z.uniforms.rotation=p.getUniformLocation(Z.program,"rotation");Z.uniforms.scale=p.getUniformLocation(Z.program,"scale");Z.uniforms.alignment=
p.getUniformLocation(Z.program,"alignment");Z.uniforms.color=p.getUniformLocation(Z.program,"color");Z.uniforms.map=p.getUniformLocation(Z.program,"map");Z.uniforms.opacity=p.getUniformLocation(Z.program,"opacity");Z.uniforms.useScreenCoordinates=p.getUniformLocation(Z.program,"useScreenCoordinates");Z.uniforms.affectedByDistance=p.getUniformLocation(Z.program,"affectedByDistance");Z.uniforms.screenPosition=p.getUniformLocation(Z.program,"screenPosition");Z.uniforms.modelViewMatrix=p.getUniformLocation(Z.program,
"modelViewMatrix");Z.uniforms.projectionMatrix=p.getUniformLocation(Z.program,"projectionMatrix");var Ja=!1;this.setSize=function(b,e){L.width=b;L.height=e;this.setViewport(0,0,L.width,L.height)};this.setViewport=function(b,e,c,f){M=b;la=e;pa=c;qa=f;p.viewport(M,la,pa,qa)};this.setScissor=function(b,e,c,f){p.scissor(b,e,c,f)};this.enableScissorTest=function(b){b?p.enable(p.SCISSOR_TEST):p.disable(p.SCISSOR_TEST)};this.setClearColorHex=function(b,e){ha.setHex(b);ra=e;p.clearColor(ha.r,ha.g,ha.b,ra)};
this.setClearColor=function(b,e){ha.copy(b);ra=e;p.clearColor(ha.r,ha.g,ha.b,ra)};this.getClearColor=function(){return ha};this.getClearAlpha=function(){return ra};this.clear=function(){p.clear(p.COLOR_BUFFER_BIT|p.DEPTH_BUFFER_BIT|p.STENCIL_BUFFER_BIT)};this.getContext=function(){return p};this.deallocateObject=function(b){if(b.__webglInit)if(b.__webglInit=!1,delete b._modelViewMatrix,delete b._normalMatrixArray,delete b._modelViewMatrixArray,delete b._objectMatrixArray,b instanceof THREE.Mesh)for(g in b.geometry.geometryGroups){var e=
b.geometry.geometryGroups[g];p.deleteBuffer(e.__webglVertexBuffer);p.deleteBuffer(e.__webglNormalBuffer);p.deleteBuffer(e.__webglTangentBuffer);p.deleteBuffer(e.__webglColorBuffer);p.deleteBuffer(e.__webglUVBuffer);p.deleteBuffer(e.__webglUV2Buffer);p.deleteBuffer(e.__webglSkinVertexABuffer);p.deleteBuffer(e.__webglSkinVertexBBuffer);p.deleteBuffer(e.__webglSkinIndicesBuffer);p.deleteBuffer(e.__webglSkinWeightsBuffer);p.deleteBuffer(e.__webglFaceBuffer);p.deleteBuffer(e.__webglLineBuffer);if(e.numMorphTargets)for(var c=
0,f=e.numMorphTargets;c<f;c++)p.deleteBuffer(e.__webglMorphTargetsBuffers[c]);V.info.memory.geometries--}else if(b instanceof THREE.Ribbon)b=b.geometry,p.deleteBuffer(b.__webglVertexBuffer),p.deleteBuffer(b.__webglColorBuffer),V.info.memory.geometries--;else if(b instanceof THREE.Line)b=b.geometry,p.deleteBuffer(b.__webglVertexBuffer),p.deleteBuffer(b.__webglColorBuffer),V.info.memory.geometries--;else if(b instanceof THREE.ParticleSystem)b=b.geometry,p.deleteBuffer(b.__webglVertexBuffer),p.deleteBuffer(b.__webglColorBuffer),
V.info.memory.geometries--};this.deallocateTexture=function(b){if(b.__webglInit)b.__webglInit=!1,p.deleteTexture(b.__webglTexture),V.info.memory.textures--};this.initMaterial=function(b,e,c,f){var h,k,m,n;b instanceof THREE.MeshDepthMaterial?n="depth":b instanceof THREE.MeshNormalMaterial?n="normal":b instanceof THREE.MeshBasicMaterial?n="basic":b instanceof THREE.MeshLambertMaterial?n="lambert":b instanceof THREE.MeshPhongMaterial?n="phong":b instanceof THREE.LineBasicMaterial?n="basic":b instanceof
THREE.ParticleBasicMaterial&&(n="particle_basic");if(n){var o=THREE.ShaderLib[n];b.uniforms=THREE.UniformsUtils.clone(o.uniforms);b.vertexShader=o.vertexShader;b.fragmentShader=o.fragmentShader}var t,w,u;t=u=o=0;for(w=e.length;t<w;t++)m=e[t],m instanceof THREE.SpotLight&&u++,m instanceof THREE.DirectionalLight&&u++,m instanceof THREE.PointLight&&o++;o+u<=Ca?t=u:(t=Math.ceil(Ca*u/(o+u)),o=Ca-t);m={directional:t,point:o};o=u=0;for(t=e.length;o<t;o++)w=e[o],w instanceof THREE.SpotLight&&w.castShadow&&
u++;var v=50;if(f!==void 0&&f instanceof THREE.SkinnedMesh)v=f.bones.length;var x;a:{t=b.fragmentShader;w=b.vertexShader;var o=b.uniforms,e=b.attributes,c={map:!!b.map,envMap:!!b.envMap,lightMap:!!b.lightMap,vertexColors:b.vertexColors,fog:c,useFog:b.fog,sizeAttenuation:b.sizeAttenuation,skinning:b.skinning,morphTargets:b.morphTargets,maxMorphTargets:this.maxMorphTargets,maxDirLights:m.directional,maxPointLights:m.point,maxBones:v,shadowMapEnabled:this.shadowMapEnabled&&f.receiveShadow,shadowMapSoft:this.shadowMapSoft,
shadowMapWidth:this.shadowMapWidth,shadowMapHeight:this.shadowMapHeight,maxShadows:u,alphaTest:b.alphaTest},L,f=[];n?f.push(n):(f.push(t),f.push(w));for(L in c)f.push(L),f.push(c[L]);n=f.join();L=0;for(f=ea.length;L<f;L++)if(ea[L].code==n){x=ea[L].program;break a}L=p.createProgram();f=[Ga?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SHADOWS "+c.maxShadows,"#define MAX_BONES "+c.maxBones,c.map?"#define USE_MAP":"",c.envMap?
A
alteredq 已提交
288
"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.skinning?"#define USE_SKINNING":"",c.morphTargets?"#define USE_MORPHTARGETS":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nuniform mat4 cameraInverseMatrix;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n");
289
m=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SHADOWS "+c.maxShadows,c.alphaTest?"#define ALPHATEST "+c.alphaTest:"",c.useFog&&c.fog?"#define USE_FOG":"",c.useFog&&c.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",c.map?"#define USE_MAP":"",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",
290 291 292 293 294 295
c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapSoft?"#define SHADOWMAP_WIDTH "+c.shadowMapWidth.toFixed(1):"",c.shadowMapSoft?"#define SHADOWMAP_HEIGHT "+c.shadowMapHeight.toFixed(1):"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");p.attachShader(L,O("fragment",m+t));p.attachShader(L,O("vertex",f+w));p.linkProgram(L);p.getProgramParameter(L,p.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+p.getProgramParameter(L,p.VALIDATE_STATUS)+", gl error ["+
p.getError()+"]");L.uniforms={};L.attributes={};var y,f=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","cameraInverseMatrix","boneGlobalMatrices","morphTargetInfluences"];for(y in o)f.push(y);y=f;f=0;for(o=y.length;f<o;f++)t=y[f],L.uniforms[t]=p.getUniformLocation(L,t);f=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(y=0;y<c.maxMorphTargets;y++)f.push("morphTarget"+y);for(x in e)f.push(x);
x=f;y=0;for(e=x.length;y<e;y++)c=x[y],L.attributes[c]=p.getAttribLocation(L,c);L.id=ea.length;ea.push({program:L,code:n});V.info.memory.programs=ea.length;x=L}b.program=x;x=b.program.attributes;x.position>=0&&p.enableVertexAttribArray(x.position);x.color>=0&&p.enableVertexAttribArray(x.color);x.normal>=0&&p.enableVertexAttribArray(x.normal);x.tangent>=0&&p.enableVertexAttribArray(x.tangent);b.skinning&&x.skinVertexA>=0&&x.skinVertexB>=0&&x.skinIndex>=0&&x.skinWeight>=0&&(p.enableVertexAttribArray(x.skinVertexA),
p.enableVertexAttribArray(x.skinVertexB),p.enableVertexAttribArray(x.skinIndex),p.enableVertexAttribArray(x.skinWeight));if(b.attributes)for(k in b.attributes)x[k]!==void 0&&x[k]>=0&&p.enableVertexAttribArray(x[k]);if(b.morphTargets)for(k=b.numSupportedMorphTargets=0;k<this.maxMorphTargets;k++)y="morphTarget"+k,x[y]>=0&&(p.enableVertexAttribArray(x[y]),b.numSupportedMorphTargets++);b.uniformsList=[];for(h in b.uniforms)b.uniformsList.push([b.uniforms[h],h])};this.clearTarget=function(b,e,c,f){X(b);
b=0;e&&(b|=p.COLOR_BUFFER_BIT);c&&(b|=p.DEPTH_BUFFER_BIT);f&&(b|=p.STENCIL_BUFFER_BIT);p.clear(b)};this.render=function(b,c,p,t){var L,W,aa,C,F,G,M,N,J=b.lights,oa=b.fog;$=-1;this.shadowMapEnabled&&A(b,c);V.info.render.calls=0;V.info.render.vertices=0;V.info.render.faces=0;c.matrixAutoUpdate&&c.update(void 0,!0);b.update(void 0,!1,c);c.matrixWorldInverse.flattenToArray(za);c.projectionMatrix.flattenToArray(Da);ua.multiply(c.projectionMatrix,c.matrixWorldInverse);u(ua);this.initWebGLObjects(b);X(p);
(this.autoClear||t)&&this.clear();F=b.__webglObjects.length;for(t=0;t<F;t++)if(L=b.__webglObjects[t],M=L.object,M.visible)if(!(M instanceof THREE.Mesh)||!M.frustumCulled||v(M)){if(M.matrixWorld.flattenToArray(M._objectMatrixArray),D(M,c,!0),w(L),L.render=!0,this.sortObjects)L.object.renderDepth?L.z=L.object.renderDepth:(Ba.copy(M.position),ua.multiplyVector3(Ba),L.z=Ba.z)}else L.render=!1;else L.render=!1;this.sortObjects&&b.__webglObjects.sort(y);G=b.__webglObjectsImmediate.length;for(t=0;t<G;t++)L=
296
b.__webglObjectsImmediate[t],M=L.object,M.visible&&(M.matrixAutoUpdate&&M.matrixWorld.flattenToArray(M._objectMatrixArray),D(M,c,!0),x(L));if(b.overrideMaterial){h(b.overrideMaterial.depthTest);H(b.overrideMaterial.blending);for(t=0;t<F;t++)if(L=b.__webglObjects[t],L.render)M=L.object,N=L.buffer,k(M),f(c,J,oa,b.overrideMaterial,N,M);for(t=0;t<G;t++)L=b.__webglObjectsImmediate[t],M=L.object,M.visible&&(k(M),W=e(c,J,oa,b.overrideMaterial,M),M.render(function(e){m(e,W,b.overrideMaterial.shading)}))}else{H(THREE.NormalBlending);
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
for(t=F-1;t>=0;t--)if(L=b.__webglObjects[t],L.render){M=L.object;N=L.buffer;aa=L.opaque;k(M);for(L=0;L<aa.count;L++)C=aa.list[L],h(C.depthTest),n(C.depthWrite),o(C.polygonOffset,C.polygonOffsetFactor,C.polygonOffsetUnits),f(c,J,oa,C,N,M)}for(t=0;t<G;t++)if(L=b.__webglObjectsImmediate[t],M=L.object,M.visible){aa=L.opaque;k(M);for(L=0;L<aa.count;L++)C=aa.list[L],h(C.depthTest),n(C.depthWrite),o(C.polygonOffset,C.polygonOffsetFactor,C.polygonOffsetUnits),W=e(c,J,oa,C,M),M.render(function(b){m(b,W,C.shading)})}for(t=
0;t<F;t++)if(L=b.__webglObjects[t],L.render){M=L.object;N=L.buffer;aa=L.transparent;k(M);for(L=0;L<aa.count;L++)C=aa.list[L],H(C.blending),h(C.depthTest),n(C.depthWrite),o(C.polygonOffset,C.polygonOffsetFactor,C.polygonOffsetUnits),f(c,J,oa,C,N,M)}for(t=0;t<G;t++)if(L=b.__webglObjectsImmediate[t],M=L.object,M.visible){aa=L.transparent;k(M);for(L=0;L<aa.count;L++)C=aa.list[L],H(C.blending),h(C.depthTest),n(C.depthWrite),o(C.polygonOffset,C.polygonOffsetFactor,C.polygonOffsetUnits),W=e(c,J,oa,C,M),
M.render(function(b){m(b,W,C.shading)})}}b.__webglSprites.length&&z(b,c);p&&p.minFilter!==THREE.NearestFilter&&p.minFilter!==THREE.LinearFilter&&E(p)};this.initWebGLObjects=function(b){if(!b.__webglObjects)b.__webglObjects=[],b.__webglObjectsImmediate=[],b.__webglSprites=[];for(;b.__objectsAdded.length;){var e=b.__objectsAdded[0],f=b,h=void 0,k=void 0,m=void 0;if(!e.__webglInit)if(e.__webglInit=!0,e._modelViewMatrix=new THREE.Matrix4,e._normalMatrixArray=new Float32Array(9),e._modelViewMatrixArray=
new Float32Array(16),e._objectMatrixArray=new Float32Array(16),e.matrixWorld.flattenToArray(e._objectMatrixArray),e instanceof THREE.Mesh)for(h in k=e.geometry,k.geometryGroups==void 0&&N(k),k.geometryGroups){if(m=k.geometryGroups[h],!m.__webglVertexBuffer){var n=m;n.__webglVertexBuffer=p.createBuffer();n.__webglNormalBuffer=p.createBuffer();n.__webglTangentBuffer=p.createBuffer();n.__webglColorBuffer=p.createBuffer();n.__webglUVBuffer=p.createBuffer();n.__webglUV2Buffer=p.createBuffer();n.__webglSkinVertexABuffer=
p.createBuffer();n.__webglSkinVertexBBuffer=p.createBuffer();n.__webglSkinIndicesBuffer=p.createBuffer();n.__webglSkinWeightsBuffer=p.createBuffer();n.__webglFaceBuffer=p.createBuffer();n.__webglLineBuffer=p.createBuffer();if(n.numMorphTargets){var o=void 0,t=void 0;n.__webglMorphTargetsBuffers=[];o=0;for(t=n.numMorphTargets;o<t;o++)n.__webglMorphTargetsBuffers.push(p.createBuffer())}V.info.memory.geometries++;for(var n=e,w=void 0,u=void 0,v=void 0,x=v=void 0,L=void 0,y=void 0,z=y=o=0,W=v=u=void 0,
v=t=W=u=w=void 0,x=n.geometry,L=x.faces,W=m.faces,w=0,u=W.length;w<u;w++)v=W[w],v=L[v],v instanceof THREE.Face3?(o+=3,y+=1,z+=3):v instanceof THREE.Face4&&(o+=4,y+=2,z+=4);for(var w=m,u=n,aa=W=L=void 0,A=void 0,aa=void 0,v=[],L=0,W=u.materials.length;L<W;L++)if(aa=u.materials[L],aa instanceof THREE.MeshFaceMaterial){aa=0;for(l=w.materials.length;aa<l;aa++)(A=w.materials[aa])&&v.push(A)}else(A=aa)&&v.push(A);w=v;m.__materials=w;a:{L=u=void 0;W=w.length;for(u=0;u<W;u++)if(L=w[u],L.map||L.lightMap||
L instanceof THREE.ShaderMaterial){u=!0;break a}u=!1}a:{W=L=void 0;v=w.length;for(L=0;L<v;L++)if(W=w[L],!(W instanceof THREE.MeshBasicMaterial&&!W.envMap||W instanceof THREE.MeshDepthMaterial)){W=W&&W.shading!=void 0&&W.shading==THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading;break a}W=!1}a:{v=L=void 0;aa=w.length;for(L=0;L<aa;L++)if(v=w[L],v.vertexColors){v=v.vertexColors;break a}v=!1}m.__vertexArray=new Float32Array(o*3);if(W)m.__normalArray=new Float32Array(o*3);if(x.hasTangents)m.__tangentArray=
new Float32Array(o*4);if(v)m.__colorArray=new Float32Array(o*3);if(u){if(x.faceUvs.length>0||x.faceVertexUvs.length>0)m.__uvArray=new Float32Array(o*2);if(x.faceUvs.length>1||x.faceVertexUvs.length>1)m.__uv2Array=new Float32Array(o*2)}if(n.geometry.skinWeights.length&&n.geometry.skinIndices.length)m.__skinVertexAArray=new Float32Array(o*4),m.__skinVertexBArray=new Float32Array(o*4),m.__skinIndexArray=new Float32Array(o*4),m.__skinWeightArray=new Float32Array(o*4);m.__faceArray=new Uint16Array(y*3+
(n.geometry.edgeFaces?n.geometry.edgeFaces.length*6:0));m.__lineArray=new Uint16Array(z*2);if(m.numMorphTargets){m.__morphTargetsArrays=[];x=0;for(L=m.numMorphTargets;x<L;x++)m.__morphTargetsArrays.push(new Float32Array(o*3))}m.__needsSmoothNormals=W==THREE.SmoothShading;m.__uvType=u;m.__vertexColorType=v;m.__normalType=W;m.__webglFaceCount=y*3+(n.geometry.edgeFaces?n.geometry.edgeFaces.length*6:0);m.__webglLineCount=z*2;x=0;for(L=w.length;x<L;x++)if(u=w[x],u.attributes){if(m.__webglCustomAttributes===
void 0)m.__webglCustomAttributes={};for(a in u.attributes){v=u.attributes[a];W={};for(t in v)W[t]=v[t];if(!W.__webglInitialized||W.createUniqueBuffers)W.__webglInitialized=!0,y=1,W.type==="v2"?y=2:W.type==="v3"?y=3:W.type==="v4"?y=4:W.type==="c"&&(y=3),W.size=y,W.array=new Float32Array(o*y),W.buffer=p.createBuffer(),W.buffer.belongsToAttribute=a,v.needsUpdate=!0,W.__original=v;m.__webglCustomAttributes[a]=W}}m.__inittedArrays=!0;k.__dirtyVertices=!0;k.__dirtyMorphTargets=!0;k.__dirtyElements=!0;k.__dirtyUvs=
!0;k.__dirtyNormals=!0;k.__dirtyTangents=!0;k.__dirtyColors=!0}}else if(e instanceof THREE.Ribbon){if(k=e.geometry,!k.__webglVertexBuffer)m=k,m.__webglVertexBuffer=p.createBuffer(),m.__webglColorBuffer=p.createBuffer(),V.info.memory.geometries++,m=k,n=m.vertices.length,m.__vertexArray=new Float32Array(n*3),m.__colorArray=new Float32Array(n*3),m.__webglVertexCount=n,k.__dirtyVertices=!0,k.__dirtyColors=!0}else if(e instanceof THREE.Line){if(k=e.geometry,!k.__webglVertexBuffer)m=k,m.__webglVertexBuffer=
p.createBuffer(),m.__webglColorBuffer=p.createBuffer(),V.info.memory.geometries++,m=k,n=m.vertices.length,m.__vertexArray=new Float32Array(n*3),m.__colorArray=new Float32Array(n*3),m.__webglLineCount=n,k.__dirtyVertices=!0,k.__dirtyColors=!0}else if(e instanceof THREE.ParticleSystem&&(k=e.geometry,!k.__webglVertexBuffer)){m=k;m.__webglVertexBuffer=p.createBuffer();m.__webglColorBuffer=p.createBuffer();V.info.geometries++;m=k;n=e;o=m.vertices.length;m.__vertexArray=new Float32Array(o*3);m.__colorArray=
new Float32Array(o*3);m.__sortArray=[];m.__webglParticleCount=o;m.__materials=n.materials;z=y=t=void 0;t=0;for(y=n.materials.length;t<y;t++)if(z=n.materials[t],z.attributes){if(m.__webglCustomAttributes===void 0)m.__webglCustomAttributes={};for(a in z.attributes){originalAttribute=z.attributes[a];attribute={};for(property in originalAttribute)attribute[property]=originalAttribute[property];if(!attribute.__webglInitialized||attribute.createUniqueBuffers)attribute.__webglInitialized=!0,size=1,attribute.type===
"v2"?size=2:attribute.type==="v3"?size=3:attribute.type==="v4"?size=4:attribute.type==="c"&&(size=3),attribute.size=size,attribute.array=new Float32Array(o*size),attribute.buffer=p.createBuffer(),attribute.buffer.belongsToAttribute=a,originalAttribute.needsUpdate=!0,attribute.__original=originalAttribute;m.__webglCustomAttributes[a]=attribute}}k.__dirtyVertices=!0;k.__dirtyColors=!0}if(!e.__webglActive){if(e instanceof THREE.Mesh)for(h in k=e.geometry,k.geometryGroups)m=k.geometryGroups[h],R(f.__webglObjects,
m,e);else e instanceof THREE.Ribbon||e instanceof THREE.Line||e instanceof THREE.ParticleSystem?(k=e.geometry,R(f.__webglObjects,k,e)):THREE.MarchingCubes!==void 0&&e instanceof THREE.MarchingCubes?f.__webglObjectsImmediate.push({object:e,opaque:{list:[],count:0},transparent:{list:[],count:0}}):e instanceof THREE.Sprite&&f.__webglSprites.push(e);e.__webglActive=!0}b.__objectsAdded.splice(0,1)}for(;b.__objectsRemoved.length;){e=b.__objectsRemoved[0];f=b;if(e instanceof THREE.Mesh||e instanceof THREE.ParticleSystem||
e instanceof THREE.Ribbon||e instanceof THREE.Line)G(f.__webglObjects,e);else if(e instanceof THREE.Sprite){f=f.__webglSprites;h=e;k=void 0;for(k=f.length-1;k>=0;k--)f[k]==h&&f.splice(k,1)}else e instanceof THREE.MarchingCubes&&G(f.__webglObjectsImmediate,e);e.__webglActive=!1;b.__objectsRemoved.splice(0,1)}e=0;for(f=b.__webglObjects.length;e<f;e++)if(k=b.__webglObjects[e].object,t=m=h=void 0,k instanceof THREE.Mesh){h=k.geometry;n=0;for(o=h.geometryGroupsList.length;n<o;n++)if(m=h.geometryGroupsList[n],
313
t=C(m),h.__dirtyVertices||h.__dirtyMorphTargets||h.__dirtyElements||h.__dirtyUvs||h.__dirtyNormals||h.__dirtyColors||h.__dirtyTangents||t)if(t=m,y=p.DYNAMIC_DRAW,z=!h.dynamic,t.__inittedArrays){var D=w=x=void 0,M=void 0,J=D=void 0,oa=void 0,ra=void 0,I=void 0,ha=A=aa=v=W=L=u=void 0,H=void 0,la=void 0,K=M=I=M=ra=oa=void 0,B=void 0,E=B=K=oa=void 0,Y=void 0,pa=E=B=K=D=D=J=I=M=E=B=K=Y=E=B=K=Y=E=B=K=void 0,T=0,O=0,qa=0,Ca=0,Z=0,S=0,P=0,na=0,X=0,Q=0,U=0,E=K=0,E=void 0,ga=t.__vertexArray,va=t.__uvArray,
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
wa=t.__uv2Array,ja=t.__normalArray,ia=t.__tangentArray,da=t.__colorArray,ca=t.__skinVertexAArray,$=t.__skinVertexBArray,ea=t.__skinIndexArray,fa=t.__skinWeightArray,ma=t.__morphTargetsArrays,xa=t.__webglCustomAttributes,B=void 0,ka=t.__faceArray,sa=t.__lineArray,Ia=t.__needsSmoothNormals,L=t.__vertexColorType,u=t.__uvType,W=t.__normalType,ua=k.geometry,Da=ua.__dirtyVertices,Aa=ua.__dirtyElements,za=ua.__dirtyUvs,Ga=ua.__dirtyNormals,Ka=ua.__dirtyTangents,Ba=ua.__dirtyColors,Fa=ua.__dirtyMorphTargets,
Ja=ua.vertices,cb=t.faces,fb=ua.faces,db=ua.faceVertexUvs[0],eb=ua.faceVertexUvs[1],Ra=ua.skinVerticesA,Sa=ua.skinVerticesB,Ta=ua.skinIndices,Ma=ua.skinWeights,La=ua.morphTargets;if(xa)for(pa in xa)xa[pa].offset=0,xa[pa].offsetSrc=0;x=0;for(w=cb.length;x<w;x++)if(D=cb[x],M=fb[D],db&&(v=db[D]),eb&&(aa=eb[D]),D=M.vertexNormals,J=M.normal,oa=M.vertexColors,ra=M.color,I=M.vertexTangents,M instanceof THREE.Face3){if(Da)A=Ja[M.a].position,ha=Ja[M.b].position,H=Ja[M.c].position,ga[O]=A.x,ga[O+1]=A.y,ga[O+
2]=A.z,ga[O+3]=ha.x,ga[O+4]=ha.y,ga[O+5]=ha.z,ga[O+6]=H.x,ga[O+7]=H.y,ga[O+8]=H.z,O+=9;if(xa)for(pa in xa)if(B=xa[pa],B.__original.needsUpdate)K=B.offset,E=B.offsetSrc,B.size===1?(B.boundTo===void 0||B.boundTo==="vertices"?(B.array[K]=B.value[M.a],B.array[K+1]=B.value[M.b],B.array[K+2]=B.value[M.c]):B.boundTo==="faces"?(E=B.value[E],B.array[K]=E,B.array[K+1]=E,B.array[K+2]=E,B.offsetSrc++):B.boundTo==="faceVertices"&&(B.array[K]=B.value[E],B.array[K+1]=B.value[E+1],B.array[K+2]=B.value[E+2],B.offsetSrc+=
3),B.offset+=3):(B.boundTo===void 0||B.boundTo==="vertices"?(A=B.value[M.a],ha=B.value[M.b],H=B.value[M.c]):B.boundTo==="faces"?(H=ha=A=E=B.value[E],B.offsetSrc++):B.boundTo==="faceVertices"&&(A=B.value[E],ha=B.value[E+1],H=B.value[E+2],B.offsetSrc+=3),B.size===2?(B.array[K]=A.x,B.array[K+1]=A.y,B.array[K+2]=ha.x,B.array[K+3]=ha.y,B.array[K+4]=H.x,B.array[K+5]=H.y,B.offset+=6):B.size===3?(B.type==="c"?(B.array[K]=A.r,B.array[K+1]=A.g,B.array[K+2]=A.b,B.array[K+3]=ha.r,B.array[K+4]=ha.g,B.array[K+
5]=ha.b,B.array[K+6]=H.r,B.array[K+7]=H.g,B.array[K+8]=H.b):(B.array[K]=A.x,B.array[K+1]=A.y,B.array[K+2]=A.z,B.array[K+3]=ha.x,B.array[K+4]=ha.y,B.array[K+5]=ha.z,B.array[K+6]=H.x,B.array[K+7]=H.y,B.array[K+8]=H.z),B.offset+=9):(B.array[K]=A.x,B.array[K+1]=A.y,B.array[K+2]=A.z,B.array[K+3]=A.w,B.array[K+4]=ha.x,B.array[K+5]=ha.y,B.array[K+6]=ha.z,B.array[K+7]=ha.w,B.array[K+8]=H.x,B.array[K+9]=H.y,B.array[K+10]=H.z,B.array[K+11]=H.w,B.offset+=12));if(Fa){K=0;for(B=La.length;K<B;K++)A=La[K].vertices[M.a].position,
ha=La[K].vertices[M.b].position,H=La[K].vertices[M.c].position,E=ma[K],E[U]=A.x,E[U+1]=A.y,E[U+2]=A.z,E[U+3]=ha.x,E[U+4]=ha.y,E[U+5]=ha.z,E[U+6]=H.x,E[U+7]=H.y,E[U+8]=H.z;U+=9}if(Ma.length)K=Ma[M.a],B=Ma[M.b],E=Ma[M.c],fa[Q]=K.x,fa[Q+1]=K.y,fa[Q+2]=K.z,fa[Q+3]=K.w,fa[Q+4]=B.x,fa[Q+5]=B.y,fa[Q+6]=B.z,fa[Q+7]=B.w,fa[Q+8]=E.x,fa[Q+9]=E.y,fa[Q+10]=E.z,fa[Q+11]=E.w,K=Ta[M.a],B=Ta[M.b],E=Ta[M.c],ea[Q]=K.x,ea[Q+1]=K.y,ea[Q+2]=K.z,ea[Q+3]=K.w,ea[Q+4]=B.x,ea[Q+5]=B.y,ea[Q+6]=B.z,ea[Q+7]=B.w,ea[Q+8]=E.x,ea[Q+
9]=E.y,ea[Q+10]=E.z,ea[Q+11]=E.w,K=Ra[M.a],B=Ra[M.b],E=Ra[M.c],ca[Q]=K.x,ca[Q+1]=K.y,ca[Q+2]=K.z,ca[Q+3]=1,ca[Q+4]=B.x,ca[Q+5]=B.y,ca[Q+6]=B.z,ca[Q+7]=1,ca[Q+8]=E.x,ca[Q+9]=E.y,ca[Q+10]=E.z,ca[Q+11]=1,K=Sa[M.a],B=Sa[M.b],E=Sa[M.c],$[Q]=K.x,$[Q+1]=K.y,$[Q+2]=K.z,$[Q+3]=1,$[Q+4]=B.x,$[Q+5]=B.y,$[Q+6]=B.z,$[Q+7]=1,$[Q+8]=E.x,$[Q+9]=E.y,$[Q+10]=E.z,$[Q+11]=1,Q+=12;if(Ba&&L)oa.length==3&&L==THREE.VertexColors?(M=oa[0],K=oa[1],B=oa[2]):B=K=M=ra,da[X]=M.r,da[X+1]=M.g,da[X+2]=M.b,da[X+3]=K.r,da[X+4]=K.g,
da[X+5]=K.b,da[X+6]=B.r,da[X+7]=B.g,da[X+8]=B.b,X+=9;if(Ka&&ua.hasTangents)oa=I[0],ra=I[1],M=I[2],ia[P]=oa.x,ia[P+1]=oa.y,ia[P+2]=oa.z,ia[P+3]=oa.w,ia[P+4]=ra.x,ia[P+5]=ra.y,ia[P+6]=ra.z,ia[P+7]=ra.w,ia[P+8]=M.x,ia[P+9]=M.y,ia[P+10]=M.z,ia[P+11]=M.w,P+=12;if(Ga&&W)if(D.length==3&&Ia)for(I=0;I<3;I++)J=D[I],ja[S]=J.x,ja[S+1]=J.y,ja[S+2]=J.z,S+=3;else for(I=0;I<3;I++)ja[S]=J.x,ja[S+1]=J.y,ja[S+2]=J.z,S+=3;if(za&&v!==void 0&&u)for(I=0;I<3;I++)D=v[I],va[qa]=D.u,va[qa+1]=D.v,qa+=2;if(za&&aa!==void 0&&u)for(I=
0;I<3;I++)D=aa[I],wa[Ca]=D.u,wa[Ca+1]=D.v,Ca+=2;Aa&&(ka[Z]=T,ka[Z+1]=T+1,ka[Z+2]=T+2,Z+=3,sa[na]=T,sa[na+1]=T+1,sa[na+2]=T,sa[na+3]=T+2,sa[na+4]=T+1,sa[na+5]=T+2,na+=6,T+=3)}else if(M instanceof THREE.Face4){if(Da)A=Ja[M.a].position,ha=Ja[M.b].position,H=Ja[M.c].position,la=Ja[M.d].position,ga[O]=A.x,ga[O+1]=A.y,ga[O+2]=A.z,ga[O+3]=ha.x,ga[O+4]=ha.y,ga[O+5]=ha.z,ga[O+6]=H.x,ga[O+7]=H.y,ga[O+8]=H.z,ga[O+9]=la.x,ga[O+10]=la.y,ga[O+11]=la.z,O+=12;if(xa)for(pa in xa)if(B=xa[pa],B.__original.needsUpdate)K=
B.offset,E=B.offsetSrc,B.size===1?(B.boundTo===void 0||B.boundTo==="vertices"?(B.array[K]=B.value[M.a],B.array[K+1]=B.value[M.b],B.array[K+2]=B.value[M.c],B.array[K+3]=B.value[M.d]):B.boundTo==="faces"?(E=B.value[E],B.array[K]=E,B.array[K+1]=E,B.array[K+2]=E,B.array[K+3]=E,B.offsetSrc++):B.boundTo==="faceVertices"&&(B.array[K]=B.value[E],B.array[K+1]=B.value[E+1],B.array[K+2]=B.value[E+2],B.array[K+3]=B.value[E+3],B.offsetSrc+=4),B.offset+=4):(B.boundTo===void 0||B.boundTo==="vertices"?(A=B.value[M.a],
ha=B.value[M.b],H=B.value[M.c],la=B.value[M.d]):B.boundTo==="faces"?(la=H=ha=A=E=B.value[E],B.offsetSrc++):B.boundTo==="faceVertices"&&(A=B.value[E],ha=B.value[E+1],H=B.value[E+2],la=B.value[E+3],B.offsetSrc+=4),B.size===2?(B.array[K]=A.x,B.array[K+1]=A.y,B.array[K+2]=ha.x,B.array[K+3]=ha.y,B.array[K+4]=H.x,B.array[K+5]=H.y,B.array[K+6]=la.x,B.array[K+7]=la.y,B.offset+=8):B.size===3?(B.type==="c"?(B.array[K]=A.r,B.array[K+1]=A.g,B.array[K+2]=A.b,B.array[K+3]=ha.r,B.array[K+4]=ha.g,B.array[K+5]=ha.b,
B.array[K+6]=H.r,B.array[K+7]=H.g,B.array[K+8]=H.b,B.array[K+9]=la.r,B.array[K+10]=la.g,B.array[K+11]=la.b):(B.array[K]=A.x,B.array[K+1]=A.y,B.array[K+2]=A.z,B.array[K+3]=ha.x,B.array[K+4]=ha.y,B.array[K+5]=ha.z,B.array[K+6]=H.x,B.array[K+7]=H.y,B.array[K+8]=H.z,B.array[K+9]=la.x,B.array[K+10]=la.y,B.array[K+11]=la.z),B.offset+=12):(B.array[K]=A.x,B.array[K+1]=A.y,B.array[K+2]=A.z,B.array[K+3]=A.w,B.array[K+4]=ha.x,B.array[K+5]=ha.y,B.array[K+6]=ha.z,B.array[K+7]=ha.w,B.array[K+8]=H.x,B.array[K+9]=
H.y,B.array[K+10]=H.z,B.array[K+11]=H.w,B.array[K+12]=la.x,B.array[K+13]=la.y,B.array[K+14]=la.z,B.array[K+15]=la.w,B.offset+=16));if(Fa){K=0;for(B=La.length;K<B;K++)A=La[K].vertices[M.a].position,ha=La[K].vertices[M.b].position,H=La[K].vertices[M.c].position,la=La[K].vertices[M.d].position,E=ma[K],E[U]=A.x,E[U+1]=A.y,E[U+2]=A.z,E[U+3]=ha.x,E[U+4]=ha.y,E[U+5]=ha.z,E[U+6]=H.x,E[U+7]=H.y,E[U+8]=H.z,E[U+9]=la.x,E[U+10]=la.y,E[U+11]=la.z;U+=12}if(Ma.length)K=Ma[M.a],B=Ma[M.b],E=Ma[M.c],Y=Ma[M.d],fa[Q]=
K.x,fa[Q+1]=K.y,fa[Q+2]=K.z,fa[Q+3]=K.w,fa[Q+4]=B.x,fa[Q+5]=B.y,fa[Q+6]=B.z,fa[Q+7]=B.w,fa[Q+8]=E.x,fa[Q+9]=E.y,fa[Q+10]=E.z,fa[Q+11]=E.w,fa[Q+12]=Y.x,fa[Q+13]=Y.y,fa[Q+14]=Y.z,fa[Q+15]=Y.w,K=Ta[M.a],B=Ta[M.b],E=Ta[M.c],Y=Ta[M.d],ea[Q]=K.x,ea[Q+1]=K.y,ea[Q+2]=K.z,ea[Q+3]=K.w,ea[Q+4]=B.x,ea[Q+5]=B.y,ea[Q+6]=B.z,ea[Q+7]=B.w,ea[Q+8]=E.x,ea[Q+9]=E.y,ea[Q+10]=E.z,ea[Q+11]=E.w,ea[Q+12]=Y.x,ea[Q+13]=Y.y,ea[Q+14]=Y.z,ea[Q+15]=Y.w,K=Ra[M.a],B=Ra[M.b],E=Ra[M.c],Y=Ra[M.d],ca[Q]=K.x,ca[Q+1]=K.y,ca[Q+2]=K.z,ca[Q+
3]=1,ca[Q+4]=B.x,ca[Q+5]=B.y,ca[Q+6]=B.z,ca[Q+7]=1,ca[Q+8]=E.x,ca[Q+9]=E.y,ca[Q+10]=E.z,ca[Q+11]=1,ca[Q+12]=Y.x,ca[Q+13]=Y.y,ca[Q+14]=Y.z,ca[Q+15]=1,K=Sa[M.a],B=Sa[M.b],E=Sa[M.c],M=Sa[M.d],$[Q]=K.x,$[Q+1]=K.y,$[Q+2]=K.z,$[Q+3]=1,$[Q+4]=B.x,$[Q+5]=B.y,$[Q+6]=B.z,$[Q+7]=1,$[Q+8]=E.x,$[Q+9]=E.y,$[Q+10]=E.z,$[Q+11]=1,$[Q+12]=M.x,$[Q+13]=M.y,$[Q+14]=M.z,$[Q+15]=1,Q+=16;if(Ba&&L)oa.length==4&&L==THREE.VertexColors?(M=oa[0],K=oa[1],B=oa[2],oa=oa[3]):oa=B=K=M=ra,da[X]=M.r,da[X+1]=M.g,da[X+2]=M.b,da[X+3]=
K.r,da[X+4]=K.g,da[X+5]=K.b,da[X+6]=B.r,da[X+7]=B.g,da[X+8]=B.b,da[X+9]=oa.r,da[X+10]=oa.g,da[X+11]=oa.b,X+=12;if(Ka&&ua.hasTangents)oa=I[0],ra=I[1],M=I[2],I=I[3],ia[P]=oa.x,ia[P+1]=oa.y,ia[P+2]=oa.z,ia[P+3]=oa.w,ia[P+4]=ra.x,ia[P+5]=ra.y,ia[P+6]=ra.z,ia[P+7]=ra.w,ia[P+8]=M.x,ia[P+9]=M.y,ia[P+10]=M.z,ia[P+11]=M.w,ia[P+12]=I.x,ia[P+13]=I.y,ia[P+14]=I.z,ia[P+15]=I.w,P+=16;if(Ga&&W)if(D.length==4&&Ia)for(I=0;I<4;I++)J=D[I],ja[S]=J.x,ja[S+1]=J.y,ja[S+2]=J.z,S+=3;else for(I=0;I<4;I++)ja[S]=J.x,ja[S+1]=
J.y,ja[S+2]=J.z,S+=3;if(za&&v!==void 0&&u)for(I=0;I<4;I++)D=v[I],va[qa]=D.u,va[qa+1]=D.v,qa+=2;if(za&&aa!==void 0&&u)for(I=0;I<4;I++)D=aa[I],wa[Ca]=D.u,wa[Ca+1]=D.v,Ca+=2;Aa&&(ka[Z]=T,ka[Z+1]=T+1,ka[Z+2]=T+3,ka[Z+3]=T+1,ka[Z+4]=T+2,ka[Z+5]=T+3,Z+=6,sa[na]=T,sa[na+1]=T+1,sa[na+2]=T,sa[na+3]=T+3,sa[na+4]=T+1,sa[na+5]=T+2,sa[na+6]=T+2,sa[na+7]=T+3,na+=8,T+=4)}Da&&(p.bindBuffer(p.ARRAY_BUFFER,t.__webglVertexBuffer),p.bufferData(p.ARRAY_BUFFER,ga,y));if(xa)for(pa in xa)B=xa[pa],B.__original.needsUpdate&&
(p.bindBuffer(p.ARRAY_BUFFER,B.buffer),p.bufferData(p.ARRAY_BUFFER,B.array,y));if(Fa){K=0;for(B=La.length;K<B;K++)p.bindBuffer(p.ARRAY_BUFFER,t.__webglMorphTargetsBuffers[K]),p.bufferData(p.ARRAY_BUFFER,ma[K],y)}Ba&&X>0&&(p.bindBuffer(p.ARRAY_BUFFER,t.__webglColorBuffer),p.bufferData(p.ARRAY_BUFFER,da,y));Ga&&(p.bindBuffer(p.ARRAY_BUFFER,t.__webglNormalBuffer),p.bufferData(p.ARRAY_BUFFER,ja,y));Ka&&ua.hasTangents&&(p.bindBuffer(p.ARRAY_BUFFER,t.__webglTangentBuffer),p.bufferData(p.ARRAY_BUFFER,ia,
y));za&&qa>0&&(p.bindBuffer(p.ARRAY_BUFFER,t.__webglUVBuffer),p.bufferData(p.ARRAY_BUFFER,va,y));za&&Ca>0&&(p.bindBuffer(p.ARRAY_BUFFER,t.__webglUV2Buffer),p.bufferData(p.ARRAY_BUFFER,wa,y));Aa&&(p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,t.__webglFaceBuffer),p.bufferData(p.ELEMENT_ARRAY_BUFFER,ka,y),p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,t.__webglLineBuffer),p.bufferData(p.ELEMENT_ARRAY_BUFFER,sa,y));Q>0&&(p.bindBuffer(p.ARRAY_BUFFER,t.__webglSkinVertexABuffer),p.bufferData(p.ARRAY_BUFFER,ca,y),p.bindBuffer(p.ARRAY_BUFFER,
t.__webglSkinVertexBBuffer),p.bufferData(p.ARRAY_BUFFER,$,y),p.bindBuffer(p.ARRAY_BUFFER,t.__webglSkinIndicesBuffer),p.bufferData(p.ARRAY_BUFFER,ea,y),p.bindBuffer(p.ARRAY_BUFFER,t.__webglSkinWeightsBuffer),p.bufferData(p.ARRAY_BUFFER,fa,y));z&&(delete t.__inittedArrays,delete t.__colorArray,delete t.__normalArray,delete t.__tangentArray,delete t.__uvArray,delete t.__uv2Array,delete t.__faceArray,delete t.__vertexArray,delete t.__lineArray,delete t.__skinVertexAArray,delete t.__skinVertexBArray,delete t.__skinIndexArray,
334
delete t.__skinWeightArray)}h.__dirtyVertices=!1;h.__dirtyMorphTargets=!1;h.__dirtyElements=!1;h.__dirtyUvs=!1;h.__dirtyNormals=!1;h.__dirtyTangents=!1;h.__dirtyColors=!1;F(m)}else if(k instanceof THREE.Ribbon){h=k.geometry;if(h.__dirtyVertices||h.__dirtyColors){k=h;m=p.DYNAMIC_DRAW;n=x=z=z=void 0;w=k.vertices;o=k.colors;u=w.length;t=o.length;L=k.__vertexArray;y=k.__colorArray;W=k.__dirtyColors;if(k.__dirtyVertices){for(z=0;z<u;z++)x=w[z].position,n=z*3,L[n]=x.x,L[n+1]=x.y,L[n+2]=x.z;p.bindBuffer(p.ARRAY_BUFFER,
335
k.__webglVertexBuffer);p.bufferData(p.ARRAY_BUFFER,L,m)}if(W){for(z=0;z<t;z++)color=o[z],n=z*3,y[n]=color.r,y[n+1]=color.g,y[n+2]=color.b;p.bindBuffer(p.ARRAY_BUFFER,k.__webglColorBuffer);p.bufferData(p.ARRAY_BUFFER,y,m)}}h.__dirtyVertices=!1;h.__dirtyColors=!1}else if(k instanceof THREE.Line){h=k.geometry;if(h.__dirtyVertices||h.__dirtyColors){k=h;m=p.DYNAMIC_DRAW;n=x=z=z=void 0;w=k.vertices;o=k.colors;u=w.length;t=o.length;L=k.__vertexArray;y=k.__colorArray;W=k.__dirtyColors;if(k.__dirtyVertices){for(z=
336 337
0;z<u;z++)x=w[z].position,n=z*3,L[n]=x.x,L[n+1]=x.y,L[n+2]=x.z;p.bindBuffer(p.ARRAY_BUFFER,k.__webglVertexBuffer);p.bufferData(p.ARRAY_BUFFER,L,m)}if(W){for(z=0;z<t;z++)color=o[z],n=z*3,y[n]=color.r,y[n+1]=color.g,y[n+2]=color.b;p.bindBuffer(p.ARRAY_BUFFER,k.__webglColorBuffer);p.bufferData(p.ARRAY_BUFFER,y,m)}}h.__dirtyVertices=!1;h.__dirtyColors=!1}else if(k instanceof THREE.ParticleSystem)h=k.geometry,t=C(h),(h.__dirtyVertices||h.__dirtyColors||k.sortParticles||t)&&c(h,p.DYNAMIC_DRAW,k),h.__dirtyVertices=
!1,h.__dirtyColors=!1,F(h)};this.setFaceCulling=function(b,e){b?(!e||e=="ccw"?p.frontFace(p.CCW):p.frontFace(p.CW),b=="back"?p.cullFace(p.BACK):b=="front"?p.cullFace(p.FRONT):p.cullFace(p.FRONT_AND_BACK),p.enable(p.CULL_FACE)):p.disable(p.CULL_FACE)};this.supportsVertexTextures=function(){return Ga}};
M
Mr.doob 已提交
338
THREE.WebGLRenderTarget=function(b,c,e){this.width=b;this.height=c;e=e||{};this.wrapS=e.wrapS!==void 0?e.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=e.wrapT!==void 0?e.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=e.magFilter!==void 0?e.magFilter:THREE.LinearFilter;this.minFilter=e.minFilter!==void 0?e.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=e.format!==void 0?e.format:THREE.RGBAFormat;this.type=e.type!==void 0?e.type:
339 340 341
THREE.UnsignedByteType;this.depthBuffer=e.depthBuffer!==void 0?e.depthBuffer:!0;this.stencilBuffer=e.stencilBuffer!==void 0?e.stencilBuffer:!0};
THREE.WebGLRenderTarget.prototype.clone=function(){var b=new THREE.WebGLRenderTarget(this.width,this.height);b.wrapS=this.wrapS;b.wrapT=this.wrapT;b.magFilter=this.magFilter;b.minFilter=this.minFilter;b.offset.copy(this.offset);b.repeat.copy(this.repeat);b.format=this.format;b.type=this.type;b.depthBuffer=this.depthBuffer;b.stencilBuffer=this.stencilBuffer;return b};THREE.WebGLRenderTargetCube=function(b,c,e){THREE.WebGLRenderTarget.call(this,b,c,e);this.activeCubeFace=0};
THREE.WebGLRenderTargetCube.prototype=new THREE.WebGLRenderTarget;THREE.WebGLRenderTargetCube.prototype.constructor=THREE.WebGLRenderTargetCube;THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=!0};THREE.RenderableVertex.prototype.copy=function(b){this.positionWorld.copy(b.positionWorld);this.positionScreen.copy(b.positionScreen)};
342 343 344
THREE.RenderableFace3=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterials=this.meshMaterials=null;this.overdraw=!1;this.uvs=[[]];this.z=null};
THREE.RenderableFace4=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.v4=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterials=this.meshMaterials=null;this.overdraw=!1;this.uvs=[[]];this.z=null};
THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.materials=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.materials=null};
345
THREE.ColorUtils={adjustHSV:function(b,c,e,f){var m=THREE.ColorUtils.__hsv;THREE.ColorUtils.rgbToHsv(b,m);m.h=THREE.ColorUtils.clamp(m.h+c,0,1);m.s=THREE.ColorUtils.clamp(m.s+e,0,1);m.v=THREE.ColorUtils.clamp(m.v+f,0,1);b.setHSV(m.h,m.s,m.v)},rgbToHsv:function(b,c){var e=b.r,f=b.g,m=b.b,k=Math.max(Math.max(e,f),m),h=Math.min(Math.min(e,f),m);if(h==k)h=e=0;else{var n=k-h,h=n/k,e=e==k?(f-m)/n:f==k?2+(m-e)/n:4+(e-f)/n;e/=6;e<0&&(e+=1);e>1&&(e-=1)}c===void 0&&(c={h:0,s:0,v:0});c.h=e;c.s=h;c.v=k;return c},
M
Mr.doob 已提交
346
clamp:function(b,c,e){return b<c?c:b>e?e:b}};THREE.ColorUtils.__hsv={h:0,s:0,v:0};
347 348 349 350 351 352 353 354
THREE.GeometryUtils={merge:function(b,c){var e,f,m=b.vertices.length,k=c instanceof THREE.Mesh?c.geometry:c,h=b.vertices,n=k.vertices,o=b.faces,u=k.faces,v=b.faceVertexUvs[0],k=k.faceVertexUvs[0];if(c instanceof THREE.Mesh)c.matrixAutoUpdate&&c.updateMatrix(),e=c.matrix,f=new THREE.Matrix4,f.extractRotation(e,c.scale);for(var t=0,x=n.length;t<x;t++){var w=new THREE.Vertex(n[t].position.clone());e&&e.multiplyVector3(w.position);h.push(w)}t=0;for(x=u.length;t<x;t++){var w=u[t],y,A,z=w.vertexNormals,
D=w.vertexColors;w instanceof THREE.Face3?y=new THREE.Face3(w.a+m,w.b+m,w.c+m):w instanceof THREE.Face4&&(y=new THREE.Face4(w.a+m,w.b+m,w.c+m,w.d+m));y.normal.copy(w.normal);f&&f.multiplyVector3(y.normal);h=0;for(n=z.length;h<n;h++)A=z[h].clone(),f&&f.multiplyVector3(A),y.vertexNormals.push(A);y.color.copy(w.color);h=0;for(n=D.length;h<n;h++)A=D[h],y.vertexColors.push(A.clone());y.materials=w.materials.slice();y.centroid.copy(w.centroid);e&&e.multiplyVector3(y.centroid);o.push(y)}t=0;for(x=k.length;t<
x;t++){e=k[t];f=[];h=0;for(n=e.length;h<n;h++)f.push(new THREE.UV(e[h].u,e[h].v));v.push(f)}},clone:function(b){var c=new THREE.Geometry,e,f=b.vertices,m=b.faces,k=b.faceVertexUvs[0],b=0;for(e=f.length;b<e;b++){var h=new THREE.Vertex(f[b].position.clone());c.vertices.push(h)}b=0;for(e=m.length;b<e;b++){var n=m[b],o,u,v=n.vertexNormals,t=n.vertexColors;n instanceof THREE.Face3?o=new THREE.Face3(n.a,n.b,n.c):n instanceof THREE.Face4&&(o=new THREE.Face4(n.a,n.b,n.c,n.d));o.normal.copy(n.normal);f=0;
for(h=v.length;f<h;f++)u=v[f],o.vertexNormals.push(u.clone());o.color.copy(n.color);f=0;for(h=t.length;f<h;f++)u=t[f],o.vertexColors.push(u.clone());o.materials=n.materials.slice();o.centroid.copy(n.centroid);c.faces.push(o)}b=0;for(e=k.length;b<e;b++){m=k[b];o=[];f=0;for(h=m.length;f<h;f++)o.push(new THREE.UV(m[f].u,m[f].v));c.faceVertexUvs[0].push(o)}return c},randomPointInTriangle:function(b,c,e){var f,m,k,h=new THREE.Vector3,n=THREE.GeometryUtils.__v1;f=THREE.GeometryUtils.random();m=THREE.GeometryUtils.random();
f+m>1&&(f=1-f,m=1-m);k=1-f-m;h.copy(b);h.multiplyScalar(f);n.copy(c);n.multiplyScalar(m);h.addSelf(n);n.copy(e);n.multiplyScalar(k);h.addSelf(n);return h},randomPointInFace:function(b,c,e){var f,m,k;if(b instanceof THREE.Face3)return f=c.vertices[b.a].position,m=c.vertices[b.b].position,k=c.vertices[b.c].position,THREE.GeometryUtils.randomPointInTriangle(f,m,k);else if(b instanceof THREE.Face4){f=c.vertices[b.a].position;m=c.vertices[b.b].position;k=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,m,c),h=THREE.GeometryUtils.triangleArea(m,k,c),b._area1=e,b._area2=h):(e=THREE.GeometryUtils.triangleArea(f,m,c),h=THREE.GeometryUtils.triangleArea(m,k,c));return THREE.GeometryUtils.random()*(e+h)<e?THREE.GeometryUtils.randomPointInTriangle(f,m,c):THREE.GeometryUtils.randomPointInTriangle(m,k,c)}},randomPointsInGeometry:function(b,c){function e(b){function e(c,f){if(f<c)return c;var h=c+Math.floor((f-c)/2);return u[h]>
b?e(c,h-1):u[h]<b?e(h+1,f):h}return e(0,u.length-1)}var f,m,k=b.faces,h=b.vertices,n=k.length,o=0,u=[],v,t,x,w;for(m=0;m<n;m++){f=k[m];if(f instanceof THREE.Face3)v=h[f.a].position,t=h[f.b].position,x=h[f.c].position,f._area=THREE.GeometryUtils.triangleArea(v,t,x);else if(f instanceof THREE.Face4)v=h[f.a].position,t=h[f.b].position,x=h[f.c].position,w=h[f.d].position,f._area1=THREE.GeometryUtils.triangleArea(v,t,w),f._area2=THREE.GeometryUtils.triangleArea(t,x,w),f._area=f._area1+f._area2;o+=f._area;
u[m]=o}f=[];h={};for(m=0;m<c;m++)n=THREE.GeometryUtils.random()*o,n=e(n),f[m]=THREE.GeometryUtils.randomPointInFace(k[n],b,!0),h[n]?h[n]+=1:h[n]=1;return f},triangleArea:function(b,c,e){var f,m=THREE.GeometryUtils.__v1;m.sub(b,c);f=m.length();m.sub(b,e);b=m.length();m.sub(c,e);e=m.length();c=0.5*(f+b+e);return Math.sqrt(c*(c-f)*(c-b)*(c-e))},random16:function(){return(65280*Math.random()+255*Math.random())/65535},center:function(b){b.computeBoundingBox();var c=new THREE.Matrix4;c.setTranslation(-0.5*
A
alteredq 已提交
355
(b.boundingBox.x[1]+b.boundingBox.x[0]),-0.5*(b.boundingBox.y[1]+b.boundingBox.y[0]),-0.5*(b.boundingBox.z[1]+b.boundingBox.z[0]));b.applyMatrix(c);b.computeBoundingBox()}};THREE.GeometryUtils.random=THREE.GeometryUtils.random16;THREE.GeometryUtils.__v1=new THREE.Vector3;
356 357
THREE.ImageUtils={loadTexture:function(b,c,e){var f=new Image,m=new THREE.Texture(f,c);f.onload=function(){m.needsUpdate=!0;e&&e(this)};f.crossOrigin="";f.src=b;return m},loadTextureCube:function(b,c,e){var f,m=[],k=new THREE.Texture(m,c),c=m.loadCount=0;for(f=b.length;c<f;++c)m[c]=new Image,m[c].onload=function(){m.loadCount+=1;if(m.loadCount==6)k.needsUpdate=!0;e&&e(this)},m[c].crossOrigin="",m[c].src=b[c];return k},getNormalMap:function(b,c){var e=function(b){var e=Math.sqrt(b[0]*b[0]+b[1]*b[1]+
b[2]*b[2]);return[b[0]/e,b[1]/e,b[2]/e]};c|=1;var f=b.width,m=b.height,k=document.createElement("canvas");k.width=f;k.height=m;var h=k.getContext("2d");h.drawImage(b,0,0);for(var n=h.getImageData(0,0,f,m).data,o=h.createImageData(f,m),u=o.data,v=0;v<f;v++)for(var t=1;t<m;t++){var x=t-1<0?m-1:t-1,w=(t+1)%m,y=v-1<0?f-1:v-1,A=(v+1)%f,z=[],D=[0,0,n[(t*f+v)*4]/255*c];z.push([-1,0,n[(t*f+y)*4]/255*c]);z.push([-1,-1,n[(x*f+y)*4]/255*c]);z.push([0,-1,n[(x*f+v)*4]/255*c]);z.push([1,-1,n[(x*f+A)*4]/255*c]);
358
z.push([1,0,n[(t*f+A)*4]/255*c]);z.push([1,1,n[(w*f+A)*4]/255*c]);z.push([0,1,n[(w*f+v)*4]/255*c]);z.push([-1,1,n[(w*f+y)*4]/255*c]);x=[];y=z.length;for(w=0;w<y;w++){var A=z[w],C=z[(w+1)%y],A=[A[0]-D[0],A[1]-D[1],A[2]-D[2]],C=[C[0]-D[0],C[1]-D[1],C[2]-D[2]];x.push(e([A[1]*C[2]-A[2]*C[1],A[2]*C[0]-A[0]*C[2],A[0]*C[1]-A[1]*C[0]]))}z=[0,0,0];for(w=0;w<x.length;w++)z[0]+=x[w][0],z[1]+=x[w][1],z[2]+=x[w][2];z[0]/=x.length;z[1]/=x.length;z[2]/=x.length;D=(t*f+v)*4;u[D]=(z[0]+1)/2*255|0;u[D+1]=(z[1]+0.5)*
359
255|0;u[D+2]=z[2]*255|0;u[D+3]=255}h.putImageData(o,0,0);return k}};THREE.SceneUtils={showHierarchy:function(b,c){THREE.SceneUtils.traverseHierarchy(b,function(b){b.visible=c})},traverseHierarchy:function(b,c){var e,f,m=b.children.length;for(f=0;f<m;f++)e=b.children[f],c(e),THREE.SceneUtils.traverseHierarchy(e,c)}};
A
alteredq 已提交
360 361
if(THREE.WebGLRenderer)THREE.ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
vertexShader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"},
A
alteredq 已提交
362 363
normal:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},enableSpecular:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},tNormal:{type:"t",value:2,texture:null},tSpecular:{type:"t",value:3,texture:null},tAO:{type:"t",value:4,texture:null},uNormalScale:{type:"f",value:1},tDisplacement:{type:"t",value:5,texture:null},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},uDiffuseColor:{type:"c",
value:new THREE.Color(15658734)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(328965)},uShininess:{type:"f",value:30},uOpacity:{type:"f",value:1}}]),fragmentShader:["uniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform float uOpacity;\nuniform bool enableDiffuse;\nuniform bool enableSpecular;\nuniform bool enableAO;\nuniform sampler2D tDiffuse;\nuniform sampler2D tNormal;\nuniform sampler2D tSpecular;\nuniform sampler2D tAO;\nuniform float uNormalScale;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;",
364
THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( vec3( 1.0 ), uOpacity );\nvec3 specularTex = vec3( 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse )\ngl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );\nif( enableAO )\ngl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;\nif( enableSpecular )\nspecularTex = texture2D( tSpecular, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\n#if MAX_POINT_LIGHTS > 0\nvec3 pointDiffuse = vec3( 0.0 );\nvec3 pointSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec3 pointVector = normalize( vPointLight[ i ].xyz );\nvec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );\nfloat pointDistance = vPointLight[ i ].w;\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );\npointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;\npointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec3 dirDiffuse = vec3( 0.0 );\nvec3 dirSpecular = vec3( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );\ndirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;\ndirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight;\n}\n#endif\nvec3 totalDiffuse = vec3( 0.0 );\nvec3 totalSpecular = vec3( 0.0 );\n#if MAX_DIR_LIGHTS > 0\ntotalDiffuse += dirDiffuse;\ntotalSpecular += dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalDiffuse += pointDiffuse;\ntotalSpecular += pointSpecular;\n#endif\ngl_FragColor.xyz = gl_FragColor.xyz * totalDiffuse + totalSpecular + ambientLightColor * uAmbientColor;",
M
Mr.doob 已提交
365
THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:"attribute vec4 tangent;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvViewPosition = -mvPosition.xyz;\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"},
366
cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertexShader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"}}};
367
THREE.Curve=function(){};THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(b){return this.getPoint(this.getUtoTmapping(b))};THREE.Curve.prototype.getPoints=function(b){b||(b=5);var c,e=[];for(c=0;c<=b;c++)e.push(this.getPoint(c/b));return e};THREE.Curve.prototype.getSpacedPoints=function(b){b||(b=5);var c,e=[];for(c=0;c<=b;c++)e.push(this.getPointAt(c/b));return e};
368 369
THREE.Curve.prototype.getLength=function(){var b=this.getLengths();return b[b.length-1]};THREE.Curve.prototype.getLengths=function(b){b||(b=200);if(this.cacheArcLengths&&this.cacheArcLengths.length==b+1)return this.cacheArcLengths;var c=[],e,f=this.getPoint(0),m,k=0;c.push(0);for(m=1;m<=b;m++)e=this.getPoint(m/b),k+=e.distanceTo(f),c.push(k),f=e;return this.cacheArcLengths=c};
THREE.Curve.prototype.getUtoTmapping=function(b,c){var e=this.getLengths(),f=0,m=e.length,k;k=c?c:b*e[m-1];time=Date.now();for(var h=0,n=m-1,o;h<=n;)if(f=Math.floor(h+(n-h)/2),o=e[f]-k,o<0)h=f+1;else if(o>0)n=f-1;else{n=f;break}f=n;if(e[f]==k)return f/(m-1);h=e[f];return e=(f+(k-h)/(e[f+1]-h))/(m-1)};THREE.Curve.prototype.getNormalVector=function(b){b=this.getTangent(b);return new THREE.Vector2(-b.y,b.x)};
370 371 372 373
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;
THREE.QuadraticBezierCurve.prototype.getPoint=function(b){var c;c=THREE.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x);b=THREE.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y);return new THREE.Vector2(c,b)};THREE.QuadraticBezierCurve.prototype.getTangent=function(b){var c;c=THREE.Curve.Utils.tangentQuadraticBezier(b,this.v0.x,this.v1.x,this.v2.x);b=THREE.Curve.Utils.tangentQuadraticBezier(b,this.v0.y,this.v1.y,this.v2.y);c=new THREE.Vector2(c,b);c.normalize();return c};
374
THREE.CubicBezierCurve=function(b,c,e,f){if(!(c instanceof THREE.Vector2))var m=Array.prototype.slice.call(arguments),b=new THREE.Vector2(m[0],m[1]),c=new THREE.Vector2(m[2],m[3]),e=new THREE.Vector2(m[4],m[5]),f=new THREE.Vector2(m[6],m[7]);this.v0=b;this.v1=c;this.v2=e;this.v3=f};THREE.CubicBezierCurve.prototype=new THREE.Curve;THREE.CubicBezierCurve.prototype.constructor=THREE.CubicBezierCurve;
375 376
THREE.CubicBezierCurve.prototype.getPoint=function(b){var c;c=THREE.Shape.Utils.b3(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x);b=THREE.Shape.Utils.b3(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y);return new THREE.Vector2(c,b)};THREE.CubicBezierCurve.prototype.getTangent=function(b){var c;c=THREE.Curve.Utils.tangentCubicBezier(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x);b=THREE.Curve.Utils.tangentCubicBezier(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y);c=new THREE.Vector2(c,b);c.normalize();return c};
THREE.SplineCurve=function(b){this.points=b};THREE.SplineCurve.prototype=new THREE.Curve;THREE.SplineCurve.prototype.constructor=THREE.SplineCurve;
377
THREE.SplineCurve.prototype.getPoint=function(b){var c=new THREE.Vector2,e=[],f=this.points,m;m=(f.length-1)*b;b=Math.floor(m);m-=b;e[0]=b==0?b:b-1;e[1]=b;e[2]=b>f.length-2?b:b+1;e[3]=b>f.length-3?b:b+2;c.x=THREE.Curve.Utils.interpolate(f[e[0]].x,f[e[1]].x,f[e[2]].x,f[e[3]].x,m);c.y=THREE.Curve.Utils.interpolate(f[e[0]].y,f[e[1]].y,f[e[2]].y,f[e[3]].y,m);return c};THREE.ArcCurve=function(b,c,e,f,m,k){this.aX=b;this.aY=c;this.aRadius=e;this.aStartAngle=f;this.aEndAngle=m;this.aClockwise=k};
378
THREE.ArcCurve.prototype=new THREE.Curve;THREE.ArcCurve.prototype.constructor=THREE.ArcCurve;THREE.ArcCurve.prototype.getPoint=function(b){var c=this.aEndAngle-this.aStartAngle;this.aClockwise||(b=1-b);b=this.aStartAngle+b*c;return new THREE.Vector2(this.aX+this.aRadius*Math.cos(b),this.aY+this.aRadius*Math.sin(b))};
379
THREE.Curve.Utils={tangentQuadraticBezier:function(b,c,e,f){return 2*(1-b)*(e-c)+2*b*(f-e)},tangentCubicBezier:function(b,c,e,f,m){return-3*c*(1-b)*(1-b)+3*e*(1-b)*(1-b)-6*b*e*(1-b)+6*b*f*(1-b)-3*b*b*f+3*b*b*m},tangentSpline:function(b){return 6*b*b-6*b+(3*b*b-4*b+1)+(-6*b*b+6*b)+(3*b*b-2*b)},interpolate:function(b,c,e,f,m){var b=(e-b)*0.5,f=(f-c)*0.5,k=m*m;return(2*c-2*e+b+f)*m*k+(-3*c+3*e-2*b-f)*k+b*m+c}};
380 381 382 383
THREE.Curve.create=function(b,c){b.prototype=new THREE.Curve;b.prototype.constructor=b;b.prototype.getPoint=c;return b};THREE.LineCurve3=THREE.Curve.create(function(b,c){this.v1=b;this.v2=c},function(b){var c=new THREE.Vector3;c.sub(v2,v1);c.multiplyScalar(b);c.addSelf(this.v1);return c});
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<e.length;){if(e[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;e<f;e++)c+=this.curves[e].getLength(),b.push(c);return this.cacheLengths=b};
384
THREE.CurvePath.prototype.getBoundingBox=function(){var b=this.getPoints(),c,e,f,m;c=e=Number.NEGATIVE_INFINITY;f=m=Number.POSITIVE_INFINITY;var k,h,n,o;o=new THREE.Vector2;h=0;for(n=b.length;h<n;h++){k=b[h];if(k.x>c)c=k.x;else if(k.x<f)f=k.x;if(k.y>e)e=k.y;else if(k.y<e)m=k.y;o.addSelf(k.x,k.y)}return{minX:f,minY:m,maxX:c,maxY:e,centroid:o.divideScalar(n)}};THREE.CurvePath.prototype.createPointsGeometry=function(b){return this.createGeometry(this.getPoints(b,!0))};
385
THREE.CurvePath.prototype.createSpacedPointsGeometry=function(b){return this.createGeometry(this.getSpacedPoints(b,!0))};THREE.CurvePath.prototype.createGeometry=function(b){for(var c=new THREE.Geometry,e=0;e<b.length;e++)c.vertices.push(new THREE.Vertex(new THREE.Vector3(b[e].x,b[e].y,0)));return c};THREE.CurvePath.prototype.addWrapPath=function(b){this.bends.push(b)};
386 387
THREE.CurvePath.prototype.getTransformedPoints=function(b,c){var e=this.getPoints(b),f,m;if(!c)c=this.bends;f=0;for(m=c.length;f<m;f++)e=this.getWrapPoints(e,c[f]);return e};THREE.CurvePath.prototype.getTransformedSpacedPoints=function(b,c){var e=this.getSpacedPoints(b),f,m;if(!c)c=this.bends;f=0;for(m=c.length;f<m;f++)e=this.getWrapPoints(e,c[f]);return e};
THREE.CurvePath.prototype.getWrapPoints=function(b,c){var e=this.getBoundingBox(),f,m,k,h,n,o;f=0;for(m=b.length;f<m;f++)k=b[f],h=k.x,n=k.y,o=h/e.maxX,o=c.getUtoTmapping(o,h),h=c.getPoint(o),n=c.getNormalVector(o).multiplyScalar(n),k.x=h.x+n.x,k.y=h.y+n.y;return b};THREE.Path=function(b){THREE.CurvePath.call(this);this.actions=[];b&&this.fromPoints(b)};THREE.Path.prototype=new THREE.CurvePath;THREE.Path.prototype.constructor=THREE.Path;
388 389
THREE.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_THRU:"splineThru",ARC:"arc"};THREE.Path.prototype.fromPoints=function(b){this.moveTo(b[0].x,b[0].y);var c,e=b.length;for(c=1;c<e;c++)this.lineTo(b[c].x,b[c].y)};THREE.Path.prototype.moveTo=function(){var b=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.MOVE_TO,args:b})};
THREE.Path.prototype.lineTo=function(b,c){var e=Array.prototype.slice.call(arguments),f=this.actions[this.actions.length-1].args;this.curves.push(new THREE.LineCurve(new THREE.Vector2(f[f.length-2],f[f.length-1]),new THREE.Vector2(b,c)));this.actions.push({action:THREE.PathActions.LINE_TO,args:e})};
390 391
THREE.Path.prototype.quadraticCurveTo=function(b,c,e,f){var m=Array.prototype.slice.call(arguments),k=this.actions[this.actions.length-1].args;this.curves.push(new THREE.QuadraticBezierCurve(new THREE.Vector2(k[k.length-2],k[k.length-1]),new THREE.Vector2(b,c),new THREE.Vector2(e,f)));this.actions.push({action:THREE.PathActions.QUADRATIC_CURVE_TO,args:m})};
THREE.Path.prototype.bezierCurveTo=function(b,c,e,f,m,k){var h=Array.prototype.slice.call(arguments),n=this.actions[this.actions.length-1].args;this.curves.push(new THREE.CubicBezierCurve(new THREE.Vector2(n[n.length-2],n[n.length-1]),new THREE.Vector2(b,c),new THREE.Vector2(e,f),new THREE.Vector2(m,k)));this.actions.push({action:THREE.PathActions.BEZIER_CURVE_TO,args:h})};
M
Mr.doob 已提交
392
THREE.Path.prototype.splineThru=function(b){var c=Array.prototype.slice.call(arguments),e=this.actions[this.actions.length-1].args,e=[new THREE.Vector2(e[e.length-2],e[e.length-1])];Array.prototype.push.apply(e,b);this.curves.push(new THREE.SplineCurve(e));this.actions.push({action:THREE.PathActions.CSPLINE_THRU,args:c})};
393 394 395 396 397 398 399 400 401
THREE.Path.prototype.arc=function(b,c,e,f,m,k){var h=Array.prototype.slice.call(arguments);this.curves.push(new THREE.ArcCurve(b,c,e,f,m,k));this.actions.push({action:THREE.PathActions.ARC,args:h})};THREE.Path.prototype.getSpacedPoints=function(b){b||(b=40);for(var c=[],e=0;e<b;e++)c.push(this.getPoint(e/b));return c};
THREE.Path.prototype.getPoints=function(b,c){var b=b||12,e=[],f,m,k,h,n,o,u,v,t,x,w,y,A;f=0;for(m=this.actions.length;f<m;f++)switch(k=this.actions[f],h=k.action,k=k.args,h){case THREE.PathActions.LINE_TO:e.push(new THREE.Vector2(k[0],k[1]));break;case THREE.PathActions.QUADRATIC_CURVE_TO:n=k[2];o=k[3];t=k[0];x=k[1];e.length>0?(h=e[e.length-1],w=h.x,y=h.y):(h=this.actions[f-1].args,w=h[h.length-2],y=h[h.length-1]);for(h=1;h<=b;h++)A=h/b,k=THREE.Shape.Utils.b2(A,w,t,n),A=THREE.Shape.Utils.b2(A,y,x,
o),e.push(new THREE.Vector2(k,A));break;case THREE.PathActions.BEZIER_CURVE_TO:n=k[4];o=k[5];t=k[0];x=k[1];u=k[2];v=k[3];e.length>0?(h=e[e.length-1],w=h.x,y=h.y):(h=this.actions[f-1].args,w=h[h.length-2],y=h[h.length-1]);for(h=1;h<=b;h++)A=h/b,k=THREE.Shape.Utils.b3(A,w,t,u,n),A=THREE.Shape.Utils.b3(A,y,x,v,o),e.push(new THREE.Vector2(k,A));break;case THREE.PathActions.CSPLINE_THRU:h=this.actions[f-1].args;h=[new THREE.Vector2(h[h.length-2],h[h.length-1])];A=b*k[0].length;h=h.concat(k[0]);k=new THREE.SplineCurve(h);
for(h=1;h<=A;h++)e.push(k.getPointAt(h/A));break;case THREE.PathActions.ARC:h=this.actions[f-1].args;n=k[0];o=k[1];u=k[2];t=k[3];A=k[4];x=!!k[5];v=h[h.length-2];w=h[h.length-1];h.length==0&&(v=w=0);y=A-t;var z=b*2;for(h=1;h<=z;h++)A=h/z,x||(A=1-A),A=t+A*y,k=v+n+u*Math.cos(A),A=w+o+u*Math.sin(A),e.push(new THREE.Vector2(k,A))}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,m,k){var h=this.getPoints(),n,o,u,v,t;n=0;for(o=h.length;n<o;n++)u=h[n],v=u.x,t=u.y,u.x=b*v+c*t+e,u.y=f*t+m*v+k;return h};
THREE.Path.prototype.debug=function(b){var c=this.getBoundingBox();b||(b=document.createElement("canvas"),b.setAttribute("width",c.maxX+100),b.setAttribute("height",c.maxY+100),document.body.appendChild(b));c=b.getContext("2d");c.fillStyle="white";c.fillRect(0,0,b.width,b.height);c.strokeStyle="black";c.beginPath();var e,f,m,b=0;for(e=this.actions.length;b<e;b++)f=this.actions[b],m=f.args,f=f.action,f!=THREE.PathActions.CSPLINE_THRU&&c[f].apply(c,m);c.stroke();c.closePath();c.strokeStyle="red";f=
this.getPoints();b=0;for(e=f.length;b<e;b++)m=f[b],c.beginPath(),c.arc(m.x,m.y,1.5,0,Math.PI*2,!1),c.stroke(),c.closePath()};
THREE.Path.prototype.toShapes=function(){var b,c,e,f,m=[],k=new THREE.Path;b=0;for(c=this.actions.length;b<c;b++)e=this.actions[b],f=e.args,e=e.action,e==THREE.PathActions.MOVE_TO&&k.actions.length!=0&&(m.push(k),k=new THREE.Path),k[e].apply(k,f);k.actions.length!=0&&m.push(k);if(m.length==0)return[];var h,k=[];if(THREE.Shape.Utils.isClockWise(m[0].getPoints())){b=0;for(c=m.length;b<c;b++)f=m[b],THREE.Shape.Utils.isClockWise(f.getPoints())?(h&&k.push(h),h=new THREE.Shape,h.actions=f.actions,h.curves=
f.curves):h.holes.push(f);k.push(h)}else{h=new THREE.Shape;b=0;for(c=m.length;b<c;b++)f=m[b],THREE.Shape.Utils.isClockWise(f.getPoints())?(h.actions=f.actions,h.curves=f.curves,k.push(h),h=new THREE.Shape):h.holes.push(f)}return k};THREE.Shape=function(){THREE.Path.apply(this,arguments);this.holes=[]};THREE.Shape.prototype=new THREE.Path;THREE.Shape.prototype.constructor=THREE.Path;THREE.Shape.prototype.extrude=function(b){return new THREE.ExtrudeGeometry(this,b)};
402 403
THREE.Shape.prototype.getPointsHoles=function(b){var c,e=this.holes.length,f=[];for(c=0;c<e;c++)f[c]=this.holes[c].getTransformedPoints(b,this.bends);return f};THREE.Shape.prototype.getSpacedPointsHoles=function(b){var c,e=this.holes.length,f=[];for(c=0;c<e;c++)f[c]=this.holes[c].getTransformedSpacedPoints(b,this.bends);return f};THREE.Shape.prototype.extractAllPoints=function(b){return{shape:this.getTransformedPoints(b),holes:this.getPointsHoles(b)}};
THREE.Shape.prototype.extractAllSpacedPoints=function(b){return{shape:this.getTransformedSpacedPoints(b),holes:this.getSpacedPointsHoles(b)}};
404 405 406 407 408
THREE.Shape.Utils={removeHoles:function(b,c){var e=b.concat(),f=e.concat(),m,k,h,n,o,u,v,t,x,w,y=[];for(o=0;o<c.length;o++){u=c[o];Array.prototype.push.apply(f,u);k=Number.POSITIVE_INFINITY;for(m=0;m<u.length;m++){x=u[m];w=[];for(t=0;t<e.length;t++)v=e[t],v=x.distanceToSquared(v),w.push(v),v<k&&(k=v,h=m,n=t)}m=n-1>=0?n-1:e.length-1;k=h-1>=0?h-1:u.length-1;var A=[u[h],e[n],e[m]];t=THREE.FontUtils.Triangulate.area(A);var z=[u[h],u[k],e[n]];x=THREE.FontUtils.Triangulate.area(z);w=n;v=h;n+=1;h+=-1;n<
0&&(n+=e.length);n%=e.length;h<0&&(h+=u.length);h%=u.length;m=n-1>=0?n-1:e.length-1;k=h-1>=0?h-1:u.length-1;A=[u[h],e[n],e[m]];A=THREE.FontUtils.Triangulate.area(A);z=[u[h],u[k],e[n]];z=THREE.FontUtils.Triangulate.area(z);t+x>A+z&&(n=w,h=v,n<0&&(n+=e.length),n%=e.length,h<0&&(h+=u.length),h%=u.length,m=n-1>=0?n-1:e.length-1,k=h-1>=0?h-1:u.length-1);t=e.slice(0,n);x=e.slice(n);w=u.slice(h);v=u.slice(0,h);k=[u[h],u[k],e[n]];y.push([u[h],e[n],e[m]]);y.push(k);e=t.concat(w).concat(v).concat(x)}return{shape:e,
isolatedPts:y,allpoints:f}},triangulateShape:function(b,c){var e=THREE.Shape.Utils.removeHoles(b,c),f=e.allpoints,m=e.isolatedPts,e=THREE.FontUtils.Triangulate(e.shape,!1),k,h,n,o,u={};k=0;for(h=f.length;k<h;k++)o=f[k].x+":"+f[k].y,u[o]!==void 0&&console.log("Duplicate point",o),u[o]=k;k=0;for(h=e.length;k<h;k++){n=e[k];for(f=0;f<3;f++)o=n[f].x+":"+n[f].y,o=u[o],o!==void 0&&(n[f]=o)}k=0;for(h=m.length;k<h;k++){n=m[k];for(f=0;f<3;f++)o=n[f].x+":"+n[f].y,o=u[o],o!==void 0&&(n[f]=o)}return e.concat(m)},
isClockWise:function(b){return THREE.FontUtils.Triangulate.area(b)<0},b2p0:function(b,c){var e=1-b;return e*e*c},b2p1:function(b,c){return 2*(1-b)*b*c},b2p2:function(b,c){return b*b*c},b2:function(b,c,e,f){return this.b2p0(b,c)+this.b2p1(b,e)+this.b2p2(b,f)},b3p0:function(b,c){var e=1-b;return e*e*e*c},b3p1:function(b,c){var e=1-b;return 3*e*e*b*c},b3p2:function(b,c){return 3*(1-b)*b*b*c},b3p3:function(b,c){return b*b*b*c},b3:function(b,c,e,f,m){return this.b3p0(b,c)+this.b3p1(b,e)+this.b3p2(b,f)+
this.b3p3(b,m)}};THREE.TextPath=function(b,c){THREE.Path.call(this);this.parameters=c||{};this.set(b)};THREE.TextPath.prototype.set=function(b,c){this.text=b;var c=c||this.parameters,e=c.curveSegments!==void 0?c.curveSegments:4,f=c.font!==void 0?c.font:"helvetiker",m=c.weight!==void 0?c.weight:"normal",k=c.style!==void 0?c.style:"normal";THREE.FontUtils.size=c.size!==void 0?c.size:100;THREE.FontUtils.divisions=e;THREE.FontUtils.face=f;THREE.FontUtils.weight=m;THREE.FontUtils.style=k};
M
Mr.doob 已提交
409
THREE.TextPath.prototype.toShapes=function(){for(var b=THREE.FontUtils.drawText(this.text).paths,c=[],e=0,f=b.length;e<f;e++)Array.prototype.push.apply(c,b[e].toShapes());return c};
410
THREE.AnimationHandler=function(){var b=[],c={},e={update:function(e){for(var c=0;c<b.length;c++)b[c].update(e)},addToUpdate:function(e){b.indexOf(e)===-1&&b.push(e)},removeFromUpdate:function(e){e=b.indexOf(e);e!==-1&&b.splice(e,1)},add:function(b){c[b.name]!==void 0&&console.log("THREE.AnimationHandler.add: Warning! "+b.name+" already exists in library. Overwriting.");c[b.name]=b;if(b.initialized!==!0){for(var e=0;e<b.hierarchy.length;e++){for(var f=0;f<b.hierarchy[e].keys.length;f++){if(b.hierarchy[e].keys[f].time<
411 412
0)b.hierarchy[e].keys[f].time=0;if(b.hierarchy[e].keys[f].rot!==void 0&&!(b.hierarchy[e].keys[f].rot instanceof THREE.Quaternion)){var n=b.hierarchy[e].keys[f].rot;b.hierarchy[e].keys[f].rot=new THREE.Quaternion(n[0],n[1],n[2],n[3])}}if(b.hierarchy[e].keys[0].morphTargets!==void 0){n={};for(f=0;f<b.hierarchy[e].keys.length;f++)for(var o=0;o<b.hierarchy[e].keys[f].morphTargets.length;o++){var u=b.hierarchy[e].keys[f].morphTargets[o];n[u]=-1}b.hierarchy[e].usedMorphTargets=n;for(f=0;f<b.hierarchy[e].keys.length;f++){var v=
{};for(u in n){for(o=0;o<b.hierarchy[e].keys[f].morphTargets.length;o++)if(b.hierarchy[e].keys[f].morphTargets[o]===u){v[u]=b.hierarchy[e].keys[f].morphTargetsInfluences[o];break}o===b.hierarchy[e].keys[f].morphTargets.length&&(v[u]=0)}b.hierarchy[e].keys[f].morphTargetsInfluences=v}}for(f=1;f<b.hierarchy[e].keys.length;f++)b.hierarchy[e].keys[f].time===b.hierarchy[e].keys[f-1].time&&(b.hierarchy[e].keys.splice(f,1),f--);for(f=1;f<b.hierarchy[e].keys.length;f++)b.hierarchy[e].keys[f].index=f}f=parseInt(b.length*
413
b.fps,10);b.JIT={};b.JIT.hierarchy=[];for(e=0;e<b.hierarchy.length;e++)b.JIT.hierarchy.push(Array(f));b.initialized=!0}},get:function(b){if(typeof b==="string")return c[b]?c[b]:(console.log("THREE.AnimationHandler.get: Couldn't find animation "+b),null)},parse:function(b){var e=[];if(b instanceof THREE.SkinnedMesh)for(var c=0;c<b.bones.length;c++)e.push(b.bones[c]);else f(b,e);return e}},f=function(b,e){e.push(b);for(var c=0;c<b.children.length;c++)f(b.children[c],e)};e.LINEAR=0;e.CATMULLROM=1;e.CATMULLROM_FORWARD=
M
Mr.doob 已提交
414
2;return e}();THREE.Animation=function(b,c,e,f){this.root=b;this.data=THREE.AnimationHandler.get(c);this.hierarchy=THREE.AnimationHandler.parse(b);this.currentTime=0;this.timeScale=1;this.isPlaying=!1;this.loop=this.isPaused=!0;this.interpolationType=e!==void 0?e:THREE.AnimationHandler.LINEAR;this.JITCompile=f!==void 0?f:!0;this.points=[];this.target=new THREE.Vector3};
415 416
THREE.Animation.prototype.play=function(b,c){if(!this.isPlaying){this.isPlaying=!0;this.loop=b!==void 0?b:!0;this.currentTime=c!==void 0?c:0;var e,f=this.hierarchy.length,m;for(e=0;e<f;e++){m=this.hierarchy[e];if(this.interpolationType!==THREE.AnimationHandler.CATMULLROM_FORWARD)m.useQuaternion=!0;m.matrixAutoUpdate=!0;if(m.animationCache===void 0)m.animationCache={},m.animationCache.prevKey={pos:0,rot:0,scl:0},m.animationCache.nextKey={pos:0,rot:0,scl:0},m.animationCache.originalMatrix=m instanceof
THREE.Bone?m.skinMatrix:m.matrix;var k=m.animationCache.prevKey;m=m.animationCache.nextKey;k.pos=this.data.hierarchy[e].keys[0];k.rot=this.data.hierarchy[e].keys[0];k.scl=this.data.hierarchy[e].keys[0];m.pos=this.getNextKeyWith("pos",e,1);m.rot=this.getNextKeyWith("rot",e,1);m.scl=this.getNextKeyWith("scl",e,1)}this.update(0)}this.isPaused=!1;THREE.AnimationHandler.addToUpdate(this)};
417 418
THREE.Animation.prototype.pause=function(){this.isPaused?THREE.AnimationHandler.addToUpdate(this):THREE.AnimationHandler.removeFromUpdate(this);this.isPaused=!this.isPaused};
THREE.Animation.prototype.stop=function(){this.isPaused=this.isPlaying=!1;THREE.AnimationHandler.removeFromUpdate(this);for(var b=0;b<this.hierarchy.length;b++)if(this.hierarchy[b].animationCache!==void 0)this.hierarchy[b]instanceof THREE.Bone?this.hierarchy[b].skinMatrix=this.hierarchy[b].animationCache.originalMatrix:this.hierarchy[b].matrix=this.hierarchy[b].animationCache.originalMatrix,delete this.hierarchy[b].animationCache};
419 420 421 422 423 424 425
THREE.Animation.prototype.update=function(b){if(this.isPlaying){var c=["pos","rot","scl"],e,f,m,k,h,n,o,u,v=this.data.JIT.hierarchy,t,x;this.currentTime+=b*this.timeScale;x=this.currentTime;t=this.currentTime%=this.data.length;u=parseInt(Math.min(t*this.data.fps,this.data.length*this.data.fps),10);for(var w=0,y=this.hierarchy.length;w<y;w++)if(b=this.hierarchy[w],o=b.animationCache,this.JITCompile&&v[w][u]!==void 0)b instanceof THREE.Bone?(b.skinMatrix=v[w][u],b.matrixAutoUpdate=!1,b.matrixWorldNeedsUpdate=
!1):(b.matrix=v[w][u],b.matrixAutoUpdate=!1,b.matrixWorldNeedsUpdate=!0);else{if(this.JITCompile)b instanceof THREE.Bone?b.skinMatrix=b.animationCache.originalMatrix:b.matrix=b.animationCache.originalMatrix;for(var A=0;A<3;A++){e=c[A];h=o.prevKey[e];n=o.nextKey[e];if(n.time<=x){if(t<x)if(this.loop){h=this.data.hierarchy[w].keys[0];for(n=this.getNextKeyWith(e,w,1);n.time<t;)h=n,n=this.getNextKeyWith(e,w,n.index+1)}else{this.stop();return}else{do h=n,n=this.getNextKeyWith(e,w,n.index+1);while(n.time<
t)}o.prevKey[e]=h;o.nextKey[e]=n}b.matrixAutoUpdate=!0;b.matrixWorldNeedsUpdate=!0;f=(t-h.time)/(n.time-h.time);m=h[e];k=n[e];if(f<0||f>1)console.log("THREE.Animation.update: Warning! Scale out of bounds:"+f+" on bone "+w),f=f<0?0:1;if(e==="pos")if(e=b.position,this.interpolationType===THREE.AnimationHandler.LINEAR)e.x=m[0]+(k[0]-m[0])*f,e.y=m[1]+(k[1]-m[1])*f,e.z=m[2]+(k[2]-m[2])*f;else{if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD)if(this.points[0]=
this.getPrevKeyWith("pos",w,h.index-1).pos,this.points[1]=m,this.points[2]=k,this.points[3]=this.getNextKeyWith("pos",w,n.index+1).pos,f=f*0.33+0.33,m=this.interpolateCatmullRom(this.points,f),e.x=m[0],e.y=m[1],e.z=m[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(m,k,b.quaternion,f);else if(e==="scl")e=b.scale,e.x=m[0]+(k[0]-m[0])*f,e.y=m[1]+(k[1]-m[1])*f,e.z=m[2]+(k[2]-m[2])*f}}if(this.JITCompile&&v[0][u]===void 0){this.hierarchy[0].update(void 0,!0);for(w=0;w<this.hierarchy.length;w++)v[w][u]=this.hierarchy[w]instanceof THREE.Bone?this.hierarchy[w].skinMatrix.clone():this.hierarchy[w].matrix.clone()}}};
THREE.Animation.prototype.interpolateCatmullRom=function(b,c){var e=[],f=[],m,k,h,n,o,u;m=(b.length-1)*c;k=Math.floor(m);m-=k;e[0]=k==0?k:k-1;e[1]=k;e[2]=k>b.length-2?k:k+1;e[3]=k>b.length-3?k:k+2;k=b[e[0]];n=b[e[1]];o=b[e[2]];u=b[e[3]];e=m*m;h=m*e;f[0]=this.interpolate(k[0],n[0],o[0],u[0],m,e,h);f[1]=this.interpolate(k[1],n[1],o[1],u[1],m,e,h);f[2]=this.interpolate(k[2],n[2],o[2],u[2],m,e,h);return f};
THREE.Animation.prototype.interpolate=function(b,c,e,f,m,k,h){b=(e-b)*0.5;f=(f-c)*0.5;return(2*(c-e)+b+f)*h+(-3*(c-e)-2*b-f)*k+b*m+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=e<f.length-1?e:f.length-1:e%=f.length;e<f.length;e++)if(f[e][b]!==void 0)return f[e];return this.data.hierarchy[c].keys[0]};
M
Mr.doob 已提交
426
THREE.Animation.prototype.getPrevKeyWith=function(b,c,e){for(var f=this.data.hierarchy[c].keys,e=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?e>0?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]};
427
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=Math.PI;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(b){if(b.movementSpeed!==void 0)this.movementSpeed=
428
b.movementSpeed;if(b.lookSpeed!==void 0)this.lookSpeed=b.lookSpeed;if(b.noFly!==void 0)this.noFly=b.noFly;if(b.lookVertical!==void 0)this.lookVertical=b.lookVertical;if(b.autoForward!==void 0)this.autoForward=b.autoForward;if(b.activeLook!==void 0)this.activeLook=b.activeLook;if(b.heightSpeed!==void 0)this.heightSpeed=b.heightSpeed;if(b.heightCoef!==void 0)this.heightCoef=b.heightCoef;if(b.heightMin!==void 0)this.heightMin=b.heightMin;if(b.heightMax!==void 0)this.heightMax=b.heightMax;if(b.constrainVertical!==
429 430 431 432 433
void 0)this.constrainVertical=b.constrainVertical;if(b.verticalMin!==void 0)this.verticalMin=b.verticalMin;if(b.verticalMax!==void 0)this.verticalMax=b.verticalMax;if(b.domElement!==void 0)this.domElement=b.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=this.autoSpeedFactor=0;this.mouseDragOn=this.freeze=this.moveRight=this.moveLeft=this.moveBackward=this.moveForward=!1;this.domElement===document?(this.viewHalfX=window.innerWidth/2,this.viewHalfY=window.innerHeight/2):(this.viewHalfX=
this.domElement.offsetWidth/2,this.viewHalfY=this.domElement.offsetHeight/2,this.domElement.setAttribute("tabindex",-1));this.onMouseDown=function(b){this.domElement!==document&&this.domElement.focus();b.preventDefault();b.stopPropagation();if(this.activeLook)switch(b.button){case 0:this.moveForward=!0;break;case 2:this.moveBackward=!0}this.mouseDragOn=!0};this.onMouseUp=function(b){b.preventDefault();b.stopPropagation();if(this.activeLook)switch(b.button){case 0:this.moveForward=!1;break;case 2:this.moveBackward=
!1}this.mouseDragOn=!1};this.onMouseMove=function(b){this.domElement===document?(this.mouseX=b.pageX-this.viewHalfX,this.mouseY=b.pageY-this.viewHalfY):(this.mouseX=b.pageX-this.domElement.offsetLeft-this.viewHalfX,this.mouseY=b.pageY-this.domElement.offsetTop-this.viewHalfY)};this.onKeyDown=function(b){switch(b.keyCode){case 38:case 87:this.moveForward=!0;break;case 37:case 65:this.moveLeft=!0;break;case 40:case 83:this.moveBackward=!0;break;case 39:case 68:this.moveRight=!0;break;case 82:this.moveUp=
!0;break;case 70:this.moveDown=!0;break;case 81:this.freeze=!this.freeze}};this.onKeyUp=function(b){switch(b.keyCode){case 38:case 87:this.moveForward=!1;break;case 37:case 65:this.moveLeft=!1;break;case 40:case 83:this.moveBackward=!1;break;case 39:case 68:this.moveRight=!1;break;case 82:this.moveUp=!1;break;case 70:this.moveDown=!1}};this.update=function(){var b=(new Date).getTime();this.tdiff=(b-this.lastUpdate)/1E3;this.lastUpdate=b;if(!this.freeze){this.autoSpeedFactor=this.heightSpeed?this.tdiff*
((this.position.y<this.heightMin?this.heightMin:this.position.y>this.heightMax?this.heightMax:this.position.y)-this.heightMin)*this.heightCoef:0;var c=this.tdiff*this.movementSpeed;(this.moveForward||this.autoForward&&!this.moveBackward)&&this.translateZ(-(c+this.autoSpeedFactor));this.moveBackward&&this.translateZ(c);this.moveLeft&&this.translateX(-c);this.moveRight&&this.translateX(c);this.moveUp&&this.translateY(c);this.moveDown&&this.translateY(-c);c=this.tdiff*this.lookSpeed;this.activeLook||
434 435
(c=0);this.lon+=this.mouseX*c;this.lookVertical&&(this.lat-=this.mouseY*c);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;var b=this.target.position,m=this.position;b.x=m.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=m.y+100*Math.cos(this.phi);b.z=m.z+100*Math.sin(this.phi)*Math.sin(this.theta)}b=1;this.constrainVertical&&(b=Math.PI/(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)/(Math.PI-0)+this.verticalMin;b=this.target.position;m=this.position;b.x=m.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=m.y+100*Math.cos(this.phi);b.z=m.z+100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this)};this.domElement.addEventListener("contextmenu",function(b){b.preventDefault()},
436 437
!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))};
438
THREE.PathCamera=function(b){function c(b,e,c,f){var h={name:c,fps:0.6,length:f,hierarchy:[]},k,m=e.getControlPointsArray(),n=e.getLength(),o=m.length,C=0;k=o-1;e={parent:-1,keys:[]};e.keys[0]={time:0,pos:m[0],rot:[0,0,0,1],scl:[1,1,1]};e.keys[k]={time:f,pos:m[k],rot:[0,0,0,1],scl:[1,1,1]};for(k=1;k<o-1;k++)C=f*n.chunks[k]/n.total,e.keys[k]={time:C,pos:m[k]};h.hierarchy[0]=e;THREE.AnimationHandler.add(h);return new THREE.Animation(b,c,THREE.AnimationHandler.CATMULLROM_FORWARD,!1)}function e(b,e){var c,
M
Mr.doob 已提交
439
f,h=new THREE.Geometry;for(c=0;c<b.points.length*e;c++)f=c/(b.points.length*e),f=b.getPoint(f),h.vertices[c]=new THREE.Vertex(new THREE.Vector3(f.x,f.y,f.z));return h}function f(b,c){var f=e(c,10),h=e(c,10),k=new THREE.LineBasicMaterial({color:16711680,linewidth:3});lineObj=new THREE.Line(f,k);particleObj=new THREE.ParticleSystem(h,new THREE.ParticleBasicMaterial({color:16755200,size:3}));lineObj.scale.set(1,1,1);b.addChild(lineObj);particleObj.scale.set(1,1,1);b.addChild(particleObj);h=new THREE.SphereGeometry(1,
440 441 442
16,8);k=new THREE.MeshBasicMaterial({color:65280});for(i=0;i<c.points.length;i++)f=new THREE.Mesh(h,k),f.position.copy(c.points[i]),f.updateMatrix(),b.addChild(f)}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.id="PathCamera"+THREE.PathCameraIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=!0;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;this.animationParent=new THREE.Object3D;this.lookSpeed=0.0050;this.lookHorizontal=
this.lookVertical=!0;this.verticalAngleMap={srcRange:[0,2*Math.PI],dstRange:[0,2*Math.PI]};this.horizontalAngleMap={srcRange:[0,2*Math.PI],dstRange:[0,2*Math.PI]};this.domElement=document;if(b){if(b.duration!==void 0)this.duration=b.duration*1E3;if(b.waypoints!==void 0)this.waypoints=b.waypoints;if(b.useConstantSpeed!==void 0)this.useConstantSpeed=b.useConstantSpeed;if(b.resamplingCoef!==void 0)this.resamplingCoef=b.resamplingCoef;if(b.createDebugPath!==void 0)this.createDebugPath=b.createDebugPath;
if(b.createDebugDummy!==void 0)this.createDebugDummy=b.createDebugDummy;if(b.lookSpeed!==void 0)this.lookSpeed=b.lookSpeed;if(b.lookVertical!==void 0)this.lookVertical=b.lookVertical;if(b.lookHorizontal!==void 0)this.lookHorizontal=b.lookHorizontal;if(b.verticalAngleMap!==void 0)this.verticalAngleMap=b.verticalAngleMap;if(b.horizontalAngleMap!==void 0)this.horizontalAngleMap=b.horizontalAngleMap;if(b.domElement!==void 0)this.domElement=b.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=
443 444
this.mouseX=0;this.domElement===document?(this.viewHalfX=window.innerWidth/2,this.viewHalfY=window.innerHeight/2):(this.viewHalfX=this.domElement.offsetWidth/2,this.viewHalfY=this.domElement.offsetHeight/2,this.domElement.setAttribute("tabindex",-1));var m=Math.PI*2,k=Math.PI/180;this.update=function(b,e,c){var f,h;this.lookHorizontal&&(this.lon+=this.mouseX*this.lookSpeed);this.lookVertical&&(this.lat-=this.mouseY*this.lookSpeed);this.lon=Math.max(0,Math.min(360,this.lon));this.lat=Math.max(-85,
Math.min(85,this.lat));this.phi=(90-this.lat)*k;this.theta=this.lon*k;f=this.phi%m;this.phi=f>=0?f:f+m;f=this.verticalAngleMap.srcRange;h=this.verticalAngleMap.dstRange;var n=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])/n)*n+h[0];f=this.horizontalAngleMap.srcRange;h=this.horizontalAngleMap.dstRange;n=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])/n)*n+h[0];f=this.target.position;
445
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.domElement===document?(this.mouseX=b.pageX-this.viewHalfX,this.mouseY=b.pageY-this.viewHalfY):(this.mouseX=b.pageX-this.domElement.offsetLeft-this.viewHalfX,this.mouseY=b.pageY-this.domElement.offsetTop-this.viewHalfY)};this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&
446
this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){var b=new THREE.MeshLambertMaterial({color:30719}),h=new THREE.MeshLambertMaterial({color:65280}),n=new THREE.CubeGeometry(10,10,20),o=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(n,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=
447 448
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=
449 450 451 452
b.autoForward;if(b.domElement!==void 0)this.domElement=b.domElement}this.useTarget=!1;this.useQuaternion=!0;this.mouseStatus=0;this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0};this.moveVector=new THREE.Vector3(0,0,0);this.rotationVector=new THREE.Vector3(0,0,0);this.lastUpdate=-1;this.tdiff=0;this.domElement!==document&&this.domElement.setAttribute("tabindex",-1);this.handleEvent=function(b){if(typeof this[b.type]=="function")this[b.type](b)};
this.keydown=function(b){if(!b.altKey){switch(b.keyCode){case 16:this.movementSpeedMultiplier=0.1;break;case 87:this.moveState.forward=1;break;case 83:this.moveState.back=1;break;case 65:this.moveState.left=1;break;case 68:this.moveState.right=1;break;case 82:this.moveState.up=1;break;case 70:this.moveState.down=1;break;case 38:this.moveState.pitchUp=1;break;case 40:this.moveState.pitchDown=1;break;case 37:this.moveState.yawLeft=1;break;case 39:this.moveState.yawRight=1;break;case 81:this.moveState.rollLeft=
1;break;case 69:this.moveState.rollRight=1}this.updateMovementVector();this.updateRotationVector()}};this.keyup=function(b){switch(b.keyCode){case 16:this.movementSpeedMultiplier=1;break;case 87:this.moveState.forward=0;break;case 83:this.moveState.back=0;break;case 65:this.moveState.left=0;break;case 68:this.moveState.right=0;break;case 82:this.moveState.up=0;break;case 70:this.moveState.down=0;break;case 38:this.moveState.pitchUp=0;break;case 40:this.moveState.pitchDown=0;break;case 37:this.moveState.yawLeft=
0;break;case 39:this.moveState.yawRight=0;break;case 81:this.moveState.rollLeft=0;break;case 69:this.moveState.rollRight=0}this.updateMovementVector();this.updateRotationVector()};this.mousedown=function(b){this.domElement!==document&&this.domElement.focus();b.preventDefault();b.stopPropagation();if(this.dragToLook)this.mouseStatus++;else switch(b.button){case 0:this.moveForward=!0;break;case 2:this.moveBackward=!0}};this.mousemove=function(b){if(!this.dragToLook||this.mouseStatus>0){var c=this.getContainerDimensions(),
453
m=c.size[0]/2,k=c.size[1]/2;this.moveState.yawLeft=-(b.pageX-c.offset[0]-m)/m;this.moveState.pitchDown=(b.pageY-c.offset[1]-k)/k;this.updateRotationVector()}};this.mouseup=function(b){b.preventDefault();b.stopPropagation();if(this.dragToLook)this.mouseStatus--,this.moveState.yawLeft=this.moveState.pitchDown=0;else switch(b.button){case 0:this.moveForward=!1;break;case 2:this.moveBackward=!1}this.updateRotationVector()};this.update=function(){var b=(new Date).getTime();if(this.lastUpdate==-1)this.lastUpdate=
454 455 456 457
b;this.tdiff=(b-this.lastUpdate)/1E3;this.lastUpdate=b;var b=this.tdiff*this.movementSpeed,c=this.tdiff*this.rollSpeed;this.translateX(this.moveVector.x*b);this.translateY(this.moveVector.y*b);this.translateZ(this.moveVector.z*b);this.tmpQuaternion.set(this.rotationVector.x*c,this.rotationVector.y*c,this.rotationVector.z*c,1).normalize();this.quaternion.multiplySelf(this.tmpQuaternion);this.matrix.setPosition(this.position);this.matrix.setRotationFromQuaternion(this.quaternion);this.matrixWorldNeedsUpdate=
!0;this.supr.update.call(this)};this.updateMovementVector=function(){var b=this.moveState.forward||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);this.domElement.addEventListener("keydown",c(this,this.keydown),!1);this.domElement.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;
458 459 460
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 m=new THREE.Vector3,k=new THREE.Vector3,h=new THREE.Vector3,n=new THREE.Matrix4,o=!1,u=1,v=0,t=0,x=0,w=0,y=0,A=window.innerWidth/2,z=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*w),this.rotateVertically(b*y));b=this.delta*this.movementSpeed;this.translateZ(b*(v>0||this.autoForward&&!(v<0)?1:v));this.translateX(b*t);this.translateY(b*x);o&&(this.roll+=this.rollSpeed*this.delta*u);if(this.forward.y>this.constrainVertical[1])this.forward.y=this.constrainVertical[1],this.forward.normalize();
else if(this.forward.y<this.constrainVertical[0])this.forward.y=this.constrainVertical[0],this.forward.normalize();h.copy(this.forward);k.set(0,1,0);m.cross(k,h).normalize();k.cross(h,m).normalize();this.matrix.n11=m.x;this.matrix.n12=k.x;this.matrix.n13=h.x;this.matrix.n21=m.y;this.matrix.n22=k.y;this.matrix.n23=h.y;this.matrix.n31=m.z;this.matrix.n32=k.z;this.matrix.n33=h.z;n.identity();n.n11=Math.cos(this.roll);n.n12=-Math.sin(this.roll);n.n21=Math.sin(this.roll);n.n22=Math.cos(this.roll);this.matrix.multiplySelf(n);
461
this.matrixWorldNeedsUpdate=!0;this.matrix.n14=this.position.x;this.matrix.n24=this.position.y;this.matrix.n34=this.position.z;this.supr.update.call(this)};this.translateX=function(b){this.position.x+=this.matrix.n11*b;this.position.y+=this.matrix.n21*b;this.position.z+=this.matrix.n31*b};this.translateY=function(b){this.position.x+=this.matrix.n12*b;this.position.y+=this.matrix.n22*b;this.position.z+=this.matrix.n32*b};this.translateZ=function(b){this.position.x-=this.matrix.n13*b;this.position.y-=
462 463 464
this.matrix.n23*b;this.position.z-=this.matrix.n33*b};this.rotateHorizontally=function(b){m.set(this.matrix.n11,this.matrix.n21,this.matrix.n31);m.multiplyScalar(b);this.forward.subSelf(m);this.forward.normalize()};this.rotateVertically=function(b){k.set(this.matrix.n12,this.matrix.n22,this.matrix.n32);k.multiplyScalar(b);this.forward.addSelf(k);this.forward.normalize()};this.domElement.addEventListener("contextmenu",function(b){b.preventDefault()},!1);this.domElement.addEventListener("mousemove",
function(b){w=(b.clientX-A)/window.innerWidth;y=(b.clientY-z)/window.innerHeight},!1);this.domElement.addEventListener("mousedown",function(b){b.preventDefault();b.stopPropagation();switch(b.button){case 0:v=1;break;case 2:v=-1}},!1);this.domElement.addEventListener("mouseup",function(b){b.preventDefault();b.stopPropagation();switch(b.button){case 0:v=0;break;case 2:v=0}},!1);this.domElement.addEventListener("keydown",function(b){switch(b.keyCode){case 38:case 87:v=1;break;case 37:case 65:t=-1;break;
case 40:case 83:v=-1;break;case 39:case 68:t=1;break;case 81:o=!0;u=1;break;case 69:o=!0;u=-1;break;case 82:x=1;break;case 70:x=-1}},!1);this.domElement.addEventListener("keyup",function(b){switch(b.keyCode){case 38:case 87:v=0;break;case 37:case 65:t=0;break;case 40:case 83:v=0;break;case 39:case 68:t=0;break;case 81:o=!1;break;case 69:o=!1;break;case 82:x=0;break;case 70:x=0}},!1)};THREE.RollCamera.prototype=new THREE.Camera;THREE.RollCamera.prototype.constructor=THREE.RollCamera;
465
THREE.RollCamera.prototype.supr=THREE.Camera.prototype;
466
THREE.TrackballCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}b=b||{};THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.domElement=b.domElement||document;this.screen=b.screen||{width:window.innerWidth,height:window.innerHeight,offsetLeft:0,offsetTop:0};this.radius=b.radius||(this.screen.width+this.screen.height)/4;this.rotateSpeed=b.rotateSpeed||1;this.zoomSpeed=b.zoomSpeed||1.2;this.panSpeed=b.panSpeed||0.3;this.noZoom=b.noZoom||!1;this.noPan=b.noPan||
467 468 469
!1;this.staticMoving=b.staticMoving||!1;this.dynamicDampingFactor=b.dynamicDampingFactor||0.2;this.minDistance=b.minDistance||0;this.maxDistance=b.maxDistance||Infinity;this.keys=b.keys||[65,83,68];this.useTarget=!0;var e=!1,f=this.STATE.NONE,m=new THREE.Vector3,k=new THREE.Vector3,h=new THREE.Vector3,n=new THREE.Vector2,o=new THREE.Vector2,u=new THREE.Vector2,v=new THREE.Vector2;this.handleEvent=function(b){if(typeof this[b.type]=="function")this[b.type](b)};this.getMouseOnScreen=function(b,c){return new THREE.Vector2((b-
this.screen.offsetLeft)/this.radius*0.5,(c-this.screen.offsetTop)/this.radius*0.5)};this.getMouseProjectionOnBall=function(b,c){var e=new THREE.Vector3((b-this.screen.width*0.5-this.screen.offsetLeft)/this.radius,(this.screen.height*0.5+this.screen.offsetTop-c)/this.radius,0),f=e.length();f>1?e.normalize():e.z=Math.sqrt(1-f*f);m=this.position.clone().subSelf(this.target.position);f=this.up.clone().setLength(e.y);f.addSelf(this.up.clone().crossSelf(m).setLength(e.x));f.addSelf(m.setLength(e.z));return f};
this.rotateCamera=function(){var b=Math.acos(k.dot(h)/k.length()/h.length());if(b){var c=(new THREE.Vector3).cross(k,h).normalize(),e=new THREE.Quaternion;b*=this.rotateSpeed;e.setFromAxisAngle(c,-b);e.multiplyVector3(m);e.multiplyVector3(this.up);e.multiplyVector3(h);this.staticMoving?k=h:(e.setFromAxisAngle(c,b*(this.dynamicDampingFactor-1)),e.multiplyVector3(k))}};this.zoomCamera=function(){var b=1+(o.y-n.y)*this.zoomSpeed;b!==1&&b>0&&(m.multiplyScalar(b),this.staticMoving?n=o:n.y+=(o.y-n.y)*this.dynamicDampingFactor)};
470 471
this.panCamera=function(){var b=v.clone().subSelf(u);if(b.lengthSq()){b.multiplyScalar(m.length()*this.panSpeed);var e=m.clone().crossSelf(this.up).setLength(b.x);e.addSelf(this.up.clone().setLength(b.y));this.position.addSelf(e);this.target.position.addSelf(e);this.staticMoving?u=v:u.addSelf(b.sub(v,u).multiplyScalar(this.dynamicDampingFactor))}};this.checkDistances=function(){if(!this.noZoom||!this.noPan)this.position.lengthSq()>this.maxDistance*this.maxDistance&&this.position.setLength(this.maxDistance),
m.lengthSq()<this.minDistance*this.minDistance&&this.position.add(this.target.position,m.setLength(this.minDistance))};this.update=function(b,e,c){m=this.position.clone().subSelf(this.target.position);this.rotateCamera();this.noZoom||this.zoomCamera();this.noPan||this.panCamera();this.position.add(this.target.position,m);this.checkDistances();this.supr.update.call(this,b,e,c)};this.domElement.addEventListener("contextmenu",function(b){b.preventDefault()},!1);this.domElement.addEventListener("mousemove",
472 473
c(this,function(b){e&&(k=h=this.getMouseProjectionOnBall(b.clientX,b.clientY),n=o=this.getMouseOnScreen(b.clientX,b.clientY),u=v=this.getMouseOnScreen(b.clientX,b.clientY),e=!1);f!==this.STATE.NONE&&(f===this.STATE.ROTATE?h=this.getMouseProjectionOnBall(b.clientX,b.clientY):f===this.STATE.ZOOM&&!this.noZoom?o=this.getMouseOnScreen(b.clientX,b.clientY):f===this.STATE.PAN&&!this.noPan&&(v=this.getMouseOnScreen(b.clientX,b.clientY)))}),!1);this.domElement.addEventListener("mousedown",c(this,function(b){b.preventDefault();
b.stopPropagation();if(f===this.STATE.NONE)f=b.button,f===this.STATE.ROTATE?k=h=this.getMouseProjectionOnBall(b.clientX,b.clientY):f===this.STATE.ZOOM&&!this.noZoom?n=o=this.getMouseOnScreen(b.clientX,b.clientY):this.noPan||(u=v=this.getMouseOnScreen(b.clientX,b.clientY))}),!1);this.domElement.addEventListener("mouseup",c(this,function(b){b.preventDefault();b.stopPropagation();f=this.STATE.NONE}),!1);window.addEventListener("keydown",c(this,function(b){if(f===this.STATE.NONE){if(b.keyCode===this.keys[this.STATE.ROTATE])f=
M
Mr.doob 已提交
474
this.STATE.ROTATE;else if(b.keyCode===this.keys[this.STATE.ZOOM]&&!this.noZoom)f=this.STATE.ZOOM;else if(b.keyCode===this.keys[this.STATE.PAN]&&!this.noPan)f=this.STATE.PAN;f!==this.STATE.NONE&&(e=!0)}}),!1);window.addEventListener("keyup",c(this,function(){if(f!==this.STATE.NONE)f=this.STATE.NONE}),!1)};THREE.TrackballCamera.prototype=new THREE.Camera;THREE.TrackballCamera.prototype.constructor=THREE.TrackballCamera;THREE.TrackballCamera.prototype.supr=THREE.Camera.prototype;
475
THREE.TrackballCamera.prototype.STATE={NONE:-1,ROTATE:0,ZOOM:1,PAN:2};THREE.QuakeCamera=THREE.FirstPersonCamera;
476
THREE.CubeGeometry=function(b,c,e,f,m,k,h,n,o){function u(b,e,c,h,n,o,t,u){var w,x,y=f||1,A=m||1,O=n/2,P=o/2,U=v.vertices.length;if(b=="x"&&e=="y"||b=="y"&&e=="x")w="z";else if(b=="x"&&e=="z"||b=="z"&&e=="x")w="y",A=k||1;else if(b=="z"&&e=="y"||b=="y"&&e=="z")w="x",y=k||1;var V=y+1,p=A+1;n/=y;var ea=o/A;for(x=0;x<p;x++)for(o=0;o<V;o++){var S=new THREE.Vector3;S[b]=(o*n-O)*c;S[e]=(x*ea-P)*h;S[w]=t;v.vertices.push(new THREE.Vertex(S))}for(x=0;x<A;x++)for(o=0;o<y;o++)v.faces.push(new THREE.Face4(o+V*
477
x+U,o+V*(x+1)+U,o+1+V*(x+1)+U,o+1+V*x+U,null,null,u)),v.faceVertexUvs[0].push([new THREE.UV(o/y,x/A),new THREE.UV(o/y,(x+1)/A),new THREE.UV((o+1)/y,(x+1)/A),new THREE.UV((o+1)/y,x/A)])}THREE.Geometry.call(this);var v=this,t=b/2,x=c/2,w=e/2,n=n?-1:1;if(h!==void 0)if(h instanceof Array)this.materials=h;else{this.materials=[];for(var y=0;y<6;y++)this.materials.push([h])}else this.materials=[];this.sides={px:!0,nx:!0,py:!0,ny:!0,pz:!0,nz:!0};if(o!=void 0)for(var A in o)this.sides[A]!=void 0&&(this.sides[A]=
478 479
o[A]);this.sides.px&&u("z","y",1*n,-1,e,c,-t,this.materials[0]);this.sides.nx&&u("z","y",-1*n,-1,e,c,t,this.materials[1]);this.sides.py&&u("x","z",1*n,1,b,e,x,this.materials[2]);this.sides.ny&&u("x","z",1*n,-1,b,e,-x,this.materials[3]);this.sides.pz&&u("x","y",1*n,-1,b,c,w,this.materials[4]);this.sides.nz&&u("x","y",-1*n,-1,b,c,-w,this.materials[5]);(function(){for(var b=[],e=[],c=0,f=v.vertices.length;c<f;c++){for(var h=v.vertices[c],k=!1,m=0,n=b.length;m<n;m++){var o=b[m];if(h.position.x==o.position.x&&
h.position.y==o.position.y&&h.position.z==o.position.z){e[c]=m;k=!0;break}}if(!k)e[c]=b.length,b.push(new THREE.Vertex(h.position.clone()))}c=0;for(f=v.faces.length;c<f;c++)h=v.faces[c],h.a=e[h.a],h.b=e[h.b],h.c=e[h.c],h.d=e[h.d];v.vertices=b})();this.computeCentroids();this.computeFaceNormals()};THREE.CubeGeometry.prototype=new THREE.Geometry;THREE.CubeGeometry.prototype.constructor=THREE.CubeGeometry;
480
THREE.CylinderGeometry=function(b,c,e,f,m,k){THREE.Geometry.call(this);var b=b!=null?b:20,c=c!=null?c:20,e=e||100,h=e/2,f=f||8,m=m||1,n,o,u=[],v=[];for(o=0;o<=m;o++){var t=[],x=[],w=o/m,y=w*(c-b)+b;for(n=0;n<=f;n++){var A=n/f;this.vertices.push(new THREE.Vertex(new THREE.Vector3(y*Math.sin(A*Math.PI*2),-w*e+h,y*Math.cos(A*Math.PI*2))));t.push(this.vertices.length-1);x.push(new THREE.UV(A,w))}u.push(t);v.push(x)}for(o=0;o<m;o++)for(n=0;n<f;n++){var e=u[o][n],t=u[o+1][n],x=u[o+1][n+1],w=u[o][n+1],y=
481 482 483
this.vertices[e].position.clone().setY(0).normalize(),A=this.vertices[t].position.clone().setY(0).normalize(),z=this.vertices[x].position.clone().setY(0).normalize(),D=this.vertices[w].position.clone().setY(0).normalize(),C=v[o][n].clone(),F=v[o+1][n].clone(),G=v[o+1][n+1].clone(),N=v[o][n+1].clone();this.faces.push(new THREE.Face4(e,t,x,w,[y,A,z,D]));this.faceVertexUvs[0].push([C,F,G,N])}if(!k&&b>0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,h,0)));for(n=0;n<f;n++)e=u[0][n],t=u[0][n+
1],x=this.vertices.length-1,y=new THREE.Vector3(0,1,0),A=new THREE.Vector3(0,1,0),z=new THREE.Vector3(0,1,0),C=v[0][n].clone(),F=v[0][n+1].clone(),G=new THREE.UV(F.u,0),this.faces.push(new THREE.Face3(e,t,x,[y,A,z])),this.faceVertexUvs[0].push([C,F,G])}if(!k&&c>0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,-h,0)));for(n=0;n<f;n++)e=u[o][n+1],t=u[o][n],x=this.vertices.length-1,y=new THREE.Vector3(0,-1,0),A=new THREE.Vector3(0,-1,0),z=new THREE.Vector3(0,-1,0),C=v[o][n+1].clone(),F=v[o][n].clone(),
G=new THREE.UV(F.u,1),this.faces.push(new THREE.Face3(e,t,x,[y,A,z])),this.faceVertexUvs[0].push([C,F,G])}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=new THREE.Geometry;THREE.CylinderGeometry.prototype.constructor=THREE.CylinderGeometry;
484
THREE.ExtrudeGeometry=function(b,c){if(typeof b!="undefined"){THREE.Geometry.call(this);var b=b instanceof Array?b:[b],e,f=b.length,m;this.shapebb=b[f-1].getBoundingBox();for(e=0;e<f;e++)m=b[e],this.addShape(m,c);this.computeCentroids();this.computeFaceNormals()}};THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
485 486 487 488 489 490 491 492
THREE.ExtrudeGeometry.prototype.addShape=function(b,c){function e(b,e,c){e||console.log("die");return e.clone().multiplyScalar(c).addSelf(b)}function f(b,e,c){var f=THREE.ExtrudeGeometry.__v1,h=THREE.ExtrudeGeometry.__v2,k=THREE.ExtrudeGeometry.__v3,m=THREE.ExtrudeGeometry.__v4,n=THREE.ExtrudeGeometry.__v5,o=THREE.ExtrudeGeometry.__v6;f.set(b.x-e.x,b.y-e.y);h.set(b.x-c.x,b.y-c.y);f=f.normalize();h=h.normalize();k.set(-f.y,f.x);m.set(h.y,-h.x);n.copy(b).addSelf(k);o.copy(b).addSelf(m);if(n.equals(o))return m.clone();
n.copy(e).addSelf(k);o.copy(c).addSelf(m);k=f.dot(m);m=o.subSelf(n).dot(m);k==0&&(console.log("Either infinite or no solutions!"),m==0?console.log("Its finite solutions."):console.log("Too bad, no solutions."));m/=k;if(m<0)return e=Math.atan2(e.y-b.y,e.x-b.x),b=Math.atan2(c.y-b.y,c.x-b.x),e>b&&(b+=Math.PI*2),anglec=(e+b)/2,new THREE.Vector2(-Math.cos(anglec),-Math.sin(anglec));return f.multiplyScalar(m).addSelf(n).subSelf(b).clone()}function m(b){for(E=b.length;--E>=0;){ma=E;fa=E-1;fa<0&&(fa=b.length-
1);for(var e=0,c=w+v*2,e=0;e<c;e++){var f=ea*e,h=ea*(e+1),k=da+ma+f,m=da+ma+h,p=k,f=da+fa+f,h=da+fa+h,t=m;p+=X;f+=X;h+=X;t+=X;I.faces.push(new THREE.Face4(p,f,h,t,null,null,G));G&&(p=e/c,f=(e+1)/c,h=n+o*2,k=(I.vertices[k].position.z+o)/h,m=(I.vertices[m].position.z+o)/h,I.faceVertexUvs[0].push([new THREE.UV(k,p),new THREE.UV(m,p),new THREE.UV(m,f),new THREE.UV(k,f)]))}}}function k(b,e,c){I.vertices.push(new THREE.Vertex(new THREE.Vector3(b,e,c)))}function h(b,e,c){b+=X;e+=X;c+=X;I.faces.push(new THREE.Face3(b,
e,c,null,null,F));if(F){var f=N.maxY,h=N.maxX,k=I.vertices[e].position.x,e=I.vertices[e].position.y,m=I.vertices[c].position.x,c=I.vertices[c].position.y;I.faceVertexUvs[0].push([new THREE.UV(I.vertices[b].position.x/h,I.vertices[b].position.y/f),new THREE.UV(k/h,e/f),new THREE.UV(m/h,c/f)])}}var n=c.amount!==void 0?c.amount:100,o=c.bevelThickness!==void 0?c.bevelThickness:6,u=c.bevelSize!==void 0?c.bevelSize:o-2,v=c.bevelSegments!==void 0?c.bevelSegments:3,t=c.bevelEnabled!==void 0?c.bevelEnabled:
!0,x=c.curveSegments!==void 0?c.curveSegments:12,w=c.steps!==void 0?c.steps:1,y=c.bendPath,A=c.extrudePath,z,D=!1,C=c.useSpacedPoints!==void 0?c.useSpacedPoints:!1,F=c.material,G=c.extrudeMaterial,N=this.shapebb;if(A)z=A.getPoints(x),w=z.length,D=!0,t=!1;t||(u=o=v=0);var R,H,J,I=this,X=this.vertices.length;y&&b.addWrapPath(y);x=C?b.extractAllSpacedPoints(x):b.extractAllPoints(x);y=x.shape;x=x.holes;if(A=!THREE.Shape.Utils.isClockWise(y)){y=y.reverse();H=0;for(J=x.length;H<J;H++)R=x[H],THREE.Shape.Utils.isClockWise(R)&&
(x[H]=R.reverse());A=!1}A=THREE.Shape.Utils.triangulateShape(y,x);C=y;H=0;for(J=x.length;H<J;H++)R=x[H],y=y.concat(R);var E,O,P,U,V,p,ea=y.length,S=A.length,ka=[];E=0;O=C.length;ma=O-1;for(fa=E+1;E<O;E++,ma++,fa++)ma==O&&(ma=0),fa==O&&(fa=0),ka[E]=f(C[E],C[ma],C[fa]);var $=[],ia,ca=ka.concat();H=0;for(J=x.length;H<J;H++){R=x[H];ia=[];E=0;O=R.length;ma=O-1;for(fa=E+1;E<O;E++,ma++,fa++)ma==O&&(ma=0),fa==O&&(fa=0),ia[E]=f(R[E],R[ma],R[fa]);$.push(ia);ca=ca.concat(ia)}for(P=0;P<v;P++){U=P/v;V=o*(1-U);
U=u*Math.sin(U*Math.PI/2);E=0;for(O=C.length;E<O;E++)p=e(C[E],ka[E],U),k(p.x,p.y,-V);H=0;for(J=x.length;H<J;H++){R=x[H];ia=$[H];E=0;for(O=R.length;E<O;E++)p=e(R[E],ia[E],U),k(p.x,p.y,-V)}}U=u;for(E=0;E<ea;E++)p=t?e(y[E],ca[E],U):y[E],D?k(p.x,p.y+z[0].y,z[0].x):k(p.x,p.y,0);for(P=1;P<=w;P++)for(E=0;E<ea;E++)p=t?e(y[E],ca[E],U):y[E],D?k(p.x,p.y+z[P-1].y,z[P-1].x):k(p.x,p.y,n/w*P);for(P=v-1;P>=0;P--){U=P/v;V=o*(1-U);U=u*Math.sin(U*Math.PI/2);E=0;for(O=C.length;E<O;E++)p=e(C[E],ka[E],U),k(p.x,p.y,n+V);
H=0;for(J=x.length;H<J;H++){R=x[H];ia=$[H];E=0;for(O=R.length;E<O;E++)p=e(R[E],ia[E],U),D?k(p.x,p.y+z[w-1].y,z[w-1].x+V):k(p.x,p.y,n+V)}}if(t){t=ea*0;for(E=0;E<S;E++)u=A[E],h(u[2]+t,u[1]+t,u[0]+t);t=ea*(w+v*2);for(E=0;E<S;E++)u=A[E],h(u[0]+t,u[1]+t,u[2]+t)}else{for(E=0;E<S;E++)u=A[E],h(u[2],u[1],u[0]);for(E=0;E<S;E++)u=A[E],h(u[0]+ea*w,u[1]+ea*w,u[2]+ea*w)}var ma,fa,da=0;m(C);da+=C.length;H=0;for(J=x.length;H<J;H++)R=x[H],m(R),da+=R.length};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;
493
THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
494
THREE.SubdivisionGeometry=function(b){function c(b,e,c,h){f.faces.push(new THREE.Face4(b,e,c,h))}function e(b,e){return Math.min(b,e)+"_"+Math.max(b,e)}THREE.Geometry.call(this);var f=this,m=b.vertices,k=b.faces,h=m.concat(),n=[],o={},u,v,t;u=0;for(v=k.length;u<v;u++)t=k[u],n.push(t.centroid),h.push(new THREE.Vertex(t.centroid));b.computeEdgeFaces();var x,w,b=b.vfMap,y=0,A=m.length,z;for(u in b)t=b[u],t=t.array,x=t[0],t=t[1],w=new THREE.Vector3,w.addSelf(n[x]),w.addSelf(n[t]),z=u.split("_"),v=z[0],
495
z=z[1],w.addSelf(m[v].position),w.addSelf(m[z].position),w.multiplyScalar(0.25),o[u]=A+k.length+y,h.push(new THREE.Vertex(w)),y++;var D;u=0;for(v=n.length;u<v;u++)t=k[u],z=A+u,t instanceof THREE.Face3?(x=e(t.a,t.b),y=e(t.b,t.c),w=e(t.c,t.a),c(z,o[x],t.b,o[y]),c(z,o[y],t.c,o[w]),c(z,o[w],t.a,o[x])):t instanceof THREE.Face4?(x=e(t.a,t.b),y=e(t.b,t.c),w=e(t.c,t.d),D=e(t.d,t.a),c(z,o[x],t.b,o[y]),c(z,o[y],t.c,o[w]),c(z,o[w],t.d,o[D]),c(z,o[D],t.a,o[x])):console.log("face should be a face!",t);f.vertices=
496
h;var C={},F={},k=function(b,e){C[b]===void 0&&(C[b]=[]);C[b].push(e)},h=function(b,e){F[b]===void 0&&(F[b]={});F[b][e]=null};for(u in b)t=b[u],z=u.split("_"),v=z[0],z=z[1],k(v,[v,z]),k(z,[v,z]),t=t.array,x=t[0],t=t[1],h(v,x),h(v,t),h(z,x),h(z,t);var b=new THREE.Vector3,k=new THREE.Vector3,G;u=0;for(v=m.length;u<v;u++)if(C[u]!==void 0){b.set(0,0,0);k.set(0,0,0);h=new THREE.Vector3(0,0,0);o=0;for(G in F[u])b.addSelf(n[G]),o++;b.divideScalar(o);o=C[u].length;for(G=0;G<o;G++)t=C[u][G],A=m[t[0]].position.clone().addSelf(m[t[1]].position).divideScalar(2),
497
k.addSelf(A);k.divideScalar(o);h.addSelf(m[u].position);h.multiplyScalar(o-3);h.addSelf(b);h.addSelf(k.multiplyScalar(2));h.divideScalar(o);this.vertices[u].position=h}this.computeCentroids();this.computeFaceNormals()};THREE.SubdivisionGeometry.prototype=new THREE.Geometry;THREE.SubdivisionGeometry.prototype.constructor=THREE.SubdivisionGeometry;
498
THREE.IcosahedronGeometry=function(b){function c(b,e,c){var f=Math.sqrt(b*b+e*e+c*c);return m.vertices.push(new THREE.Vertex(new THREE.Vector3(b/f,e/f,c/f)))-1}function e(b,e,c,f){f.faces.push(new THREE.Face3(b,e,c))}function f(b,e){var f=m.vertices[b].position,h=m.vertices[e].position;return c((f.x+h.x)/2,(f.y+h.y)/2,(f.z+h.z)/2)}var m=this,k=new THREE.Geometry;this.subdivisions=b||0;THREE.Geometry.call(this);b=(1+Math.sqrt(5))/2;c(-1,b,0);c(1,b,0);c(-1,-b,0);c(1,-b,0);c(0,-1,b);c(0,1,b);c(0,-1,
499 500 501 502 503
-b);c(0,1,-b);c(b,0,-1);c(b,0,1);c(-b,0,-1);c(-b,0,1);e(0,11,5,k);e(0,5,1,k);e(0,1,7,k);e(0,7,10,k);e(0,10,11,k);e(1,5,9,k);e(5,11,4,k);e(11,10,2,k);e(10,7,6,k);e(7,1,8,k);e(3,9,4,k);e(3,4,2,k);e(3,2,6,k);e(3,6,8,k);e(3,8,9,k);e(4,9,5,k);e(2,4,11,k);e(6,2,10,k);e(8,6,7,k);e(9,8,1,k);for(var h=0;h<this.subdivisions;h++){var b=new THREE.Geometry,n;for(n in k.faces){var o=f(k.faces[n].a,k.faces[n].b),u=f(k.faces[n].b,k.faces[n].c),v=f(k.faces[n].c,k.faces[n].a);e(k.faces[n].a,o,v,b);e(k.faces[n].b,u,
o,b);e(k.faces[n].c,v,u,b);e(o,u,v,b)}k.faces=b.faces}m.faces=k.faces;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.IcosahedronGeometry.prototype=new THREE.Geometry;THREE.IcosahedronGeometry.prototype.constructor=THREE.IcosahedronGeometry;
THREE.LatheGeometry=function(b,c,e){THREE.Geometry.call(this);this.steps=c||12;this.angle=e||2*Math.PI;for(var c=this.angle/this.steps,e=[],f=[],m=[],k=[],h=(new THREE.Matrix4).setRotationZ(c),n=0;n<b.length;n++)this.vertices.push(new THREE.Vertex(b[n])),e[n]=b[n].clone(),f[n]=this.vertices.length-1;for(var o=0;o<=this.angle+0.0010;o+=c){for(n=0;n<e.length;n++)o<this.angle?(e[n]=h.multiplyVector3(e[n].clone()),this.vertices.push(new THREE.Vertex(e[n])),m[n]=this.vertices.length-1):m=k;o==0&&(k=f);
for(n=0;n<f.length-1;n++)this.faces.push(new THREE.Face4(m[n],m[n+1],f[n+1],f[n])),this.faceVertexUvs[0].push([new THREE.UV(1-o/this.angle,n/b.length),new THREE.UV(1-o/this.angle,(n+1)/b.length),new THREE.UV(1-(o-c)/this.angle,(n+1)/b.length),new THREE.UV(1-(o-c)/this.angle,n/b.length)]);f=m;m=[]}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=new THREE.Geometry;THREE.LatheGeometry.prototype.constructor=THREE.LatheGeometry;
THREE.PlaneGeometry=function(b,c,e,f){THREE.Geometry.call(this);var m,k=b/2,h=c/2,e=e||1,f=f||1,n=e+1,o=f+1;b/=e;var u=c/f;for(m=0;m<o;m++)for(c=0;c<n;c++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(c*b-k,-(m*u-h),0)));for(m=0;m<f;m++)for(c=0;c<e;c++)this.faces.push(new THREE.Face4(c+n*m,c+n*(m+1),c+1+n*(m+1),c+1+n*m)),this.faceVertexUvs[0].push([new THREE.UV(c/e,m/f),new THREE.UV(c/e,(m+1)/f),new THREE.UV((c+1)/e,(m+1)/f),new THREE.UV((c+1)/e,m/f)]);this.computeCentroids();this.computeFaceNormals()};
504
THREE.PlaneGeometry.prototype=new THREE.Geometry;THREE.PlaneGeometry.prototype.constructor=THREE.PlaneGeometry;
505 506 507
THREE.SphereGeometry=function(b,c,e){THREE.Geometry.call(this);for(var b=b||50,f,m=Math.PI,k=Math.max(3,c||8),h=Math.max(2,e||6),c=[],e=0;e<h+1;e++){f=e/h;var n=b*Math.cos(f*m),o=b*Math.sin(f*m),u=[],v=0;for(f=0;f<k;f++){var t=2*f/k,x=o*Math.sin(t*m),t=o*Math.cos(t*m);(e==0||e==h)&&f>0||(v=this.vertices.push(new THREE.Vertex(new THREE.Vector3(t,n,x)))-1);u.push(v)}c.push(u)}for(var w,y,A,m=c.length,e=0;e<m;e++)if(k=c[e].length,e>0)for(f=0;f<k;f++){u=f==k-1;h=c[e][u?0:f+1];n=c[e][u?k-1:f];o=c[e-1][u?
k-1:f];u=c[e-1][u?0:f+1];x=e/(m-1);w=(e-1)/(m-1);y=(f+1)/k;var t=f/k,v=new THREE.UV(1-y,x),x=new THREE.UV(1-t,x),t=new THREE.UV(1-t,w),z=new THREE.UV(1-y,w);e<c.length-1&&(w=this.vertices[h].position.clone(),y=this.vertices[n].position.clone(),A=this.vertices[o].position.clone(),w.normalize(),y.normalize(),A.normalize(),this.faces.push(new THREE.Face3(h,n,o,[new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(y.x,y.y,y.z),new THREE.Vector3(A.x,A.y,A.z)])),this.faceVertexUvs[0].push([v,x,t]));e>1&&(w=
this.vertices[h].position.clone(),y=this.vertices[o].position.clone(),A=this.vertices[u].position.clone(),w.normalize(),y.normalize(),A.normalize(),this.faces.push(new THREE.Face3(h,o,u,[new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(y.x,y.y,y.z),new THREE.Vector3(A.x,A.y,A.z)])),this.faceVertexUvs[0].push([v,t,z]))}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:b}};THREE.SphereGeometry.prototype=new THREE.Geometry;
508 509 510
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;
511
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=
512
this.getFace(),e=this.size/c.resolution,f=0,m=String(b).split(""),k=m.length,h=[],b=0;b<k;b++){var n=new THREE.Path,n=this.extractGlyphPoints(m[b],c,e,f,n);f+=n.offset;h.push(n.path)}return{paths:h,offset:f/2}},extractGlyphPoints:function(b,c,e,f,m){var k=[],h,n,o,u,v,t,x,w,y,A,z=c.glyphs[b]||c.glyphs[ctxt.options.fallbackCharacter];if(z){if(z.o){c=z._cachedOutline||(z._cachedOutline=z.o.split(" "));o=c.length;for(b=0;b<o;)switch(n=c[b++],n){case "m":n=c[b++]*e+f;u=c[b++]*e;k.push(new THREE.Vector2(n,
513 514 515 516
u));m.moveTo(n,u);break;case "l":n=c[b++]*e+f;u=c[b++]*e;k.push(new THREE.Vector2(n,u));m.lineTo(n,u);break;case "q":n=c[b++]*e+f;u=c[b++]*e;x=c[b++]*e+f;w=c[b++]*e;m.quadraticCurveTo(x,w,n,u);if(h=k[k.length-1]){v=h.x;t=h.y;h=1;for(divisions=this.divisions;h<=divisions;h++){var D=h/divisions,C=THREE.Shape.Utils.b2(D,v,x,n),D=THREE.Shape.Utils.b2(D,t,w,u);k.push(new THREE.Vector2(C,D))}}break;case "b":if(n=c[b++]*e+f,u=c[b++]*e,x=c[b++]*e+f,w=c[b++]*-e,y=c[b++]*e+f,A=c[b++]*-e,m.bezierCurveTo(n,u,
x,w,y,A),h=k[k.length-1]){v=h.x;t=h.y;h=1;for(divisions=this.divisions;h<=divisions;h++)D=h/divisions,C=THREE.Shape.Utils.b3(D,v,x,y,n),D=THREE.Shape.Utils.b3(D,t,w,A,u),k.push(new THREE.Vector2(C,D))}}}return{offset:z.ha*e,points:k,path:m}}}};
(function(b){var c=function(b){for(var c=b.length,m=0,k=c-1,h=0;h<c;k=h++)m+=b[k].x*b[h].y-b[h].x*b[k].y;return m*0.5};b.Triangulate=function(b,f){var m=b.length;if(m<3)return null;var k=[],h=[],n=[],o,u,v;if(c(b)>0)for(u=0;u<m;u++)h[u]=u;else for(u=0;u<m;u++)h[u]=m-1-u;var t=2*m;for(u=m-1;m>2;){if(t--<=0){console.log("Warning, unable to triangulate polygon!");if(f)return n;return k}o=u;m<=o&&(o=0);u=o+1;m<=u&&(u=0);v=u+1;m<=v&&(v=0);var x;a:{x=b;var w=o,y=u,A=v,z=m,D=h,C=void 0,F=void 0,G=void 0,
N=void 0,R=void 0,H=void 0,J=void 0,I=void 0,X=void 0,F=x[D[w]].x,G=x[D[w]].y,N=x[D[y]].x,R=x[D[y]].y,H=x[D[A]].x,J=x[D[A]].y;if(1.0E-10>(N-F)*(J-G)-(R-G)*(H-F))x=!1;else{for(C=0;C<z;C++)if(!(C==w||C==y||C==A)){var I=x[D[C]].x,X=x[D[C]].y,E=void 0,O=void 0,P=void 0,U=void 0,V=void 0,p=void 0,ea=void 0,S=void 0,ka=void 0,$=void 0,ia=void 0,ca=void 0,E=P=V=void 0,E=H-N,O=J-R,P=F-H,U=G-J,V=N-F,p=R-G,ea=I-F,S=X-G,ka=I-N,$=X-R,ia=I-H,ca=X-J,E=E*$-O*ka,V=V*S-p*ea,P=P*ca-U*ia;if(E>=0&&P>=0&&V>=0){x=!1;break a}}x=
517 518 519 520
!0}}if(x){k.push([b[h[o]],b[h[u]],b[h[v]]]);n.push([h[o],h[u],h[v]]);o=u;for(v=u+1;v<m;o++,v++)h[o]=h[v];m--;t=2*m}}if(f)return n;return k};b.Triangulate.area=c;return b})(THREE.FontUtils);self._typeface_js={faces:THREE.FontUtils.faces,loadFace:THREE.FontUtils.loadFace};
THREE.TorusGeometry=function(b,c,e,f,m){THREE.Geometry.call(this);this.radius=b||100;this.tube=c||40;this.segmentsR=e||8;this.segmentsT=f||6;this.arc=m||Math.PI*2;m=new THREE.Vector3;b=[];c=[];for(e=0;e<=this.segmentsR;e++)for(f=0;f<=this.segmentsT;f++){var k=f/this.segmentsT*this.arc,h=e/this.segmentsR*Math.PI*2;m.x=this.radius*Math.cos(k);m.y=this.radius*Math.sin(k);var n=new THREE.Vector3;n.x=(this.radius+this.tube*Math.cos(h))*Math.cos(k);n.y=(this.radius+this.tube*Math.cos(h))*Math.sin(k);n.z=
this.tube*Math.sin(h);this.vertices.push(new THREE.Vertex(n));b.push(new THREE.UV(f/this.segmentsT,1-e/this.segmentsR));c.push(n.clone().subSelf(m).normalize())}for(e=1;e<=this.segmentsR;e++)for(f=1;f<=this.segmentsT;f++){var m=(this.segmentsT+1)*e+f-1,k=(this.segmentsT+1)*(e-1)+f-1,h=(this.segmentsT+1)*(e-1)+f,n=(this.segmentsT+1)*e+f,o=new THREE.Face4(m,k,h,n,[c[m],c[k],c[h],c[n]]);o.normal.addSelf(c[m]);o.normal.addSelf(c[k]);o.normal.addSelf(c[h]);o.normal.addSelf(c[n]);o.normal.normalize();this.faces.push(o);
this.faceVertexUvs[0].push([b[m].clone(),b[k].clone(),b[h].clone(),b[n].clone()])}this.computeCentroids()};THREE.TorusGeometry.prototype=new THREE.Geometry;THREE.TorusGeometry.prototype.constructor=THREE.TorusGeometry;
521
THREE.TorusKnotGeometry=function(b,c,e,f,m,k,h){function n(b,e,c,f,h,k){e=c/f*b;c=Math.cos(e);return new THREE.Vector3(h*(2+c)*0.5*Math.cos(b),h*(2+c)*Math.sin(b)*0.5,k*h*Math.sin(e)*0.5)}THREE.Geometry.call(this);this.radius=b||200;this.tube=c||40;this.segmentsR=e||64;this.segmentsT=f||8;this.p=m||2;this.q=k||3;this.heightScale=h||1;this.grid=Array(this.segmentsR);e=new THREE.Vector3;f=new THREE.Vector3;k=new THREE.Vector3;for(b=0;b<this.segmentsR;++b){this.grid[b]=Array(this.segmentsT);for(c=0;c<
522 523
this.segmentsT;++c){var o=b/this.segmentsR*2*this.p*Math.PI,h=c/this.segmentsT*2*Math.PI,m=n(o,h,this.q,this.p,this.radius,this.heightScale),o=n(o+0.01,h,this.q,this.p,this.radius,this.heightScale);e.x=o.x-m.x;e.y=o.y-m.y;e.z=o.z-m.z;f.x=o.x+m.x;f.y=o.y+m.y;f.z=o.z+m.z;k.cross(e,f);f.cross(k,e);k.normalize();f.normalize();o=-this.tube*Math.cos(h);h=this.tube*Math.sin(h);m.x+=o*f.x+h*k.x;m.y+=o*f.y+h*k.y;m.z+=o*f.z+h*k.z;this.grid[b][c]=this.vertices.push(new THREE.Vertex(new THREE.Vector3(m.x,m.y,
m.z)))-1}}for(b=0;b<this.segmentsR;++b)for(c=0;c<this.segmentsT;++c){var f=(b+1)%this.segmentsR,k=(c+1)%this.segmentsT,m=this.grid[b][c],e=this.grid[f][c],f=this.grid[f][k],k=this.grid[b][k],h=new THREE.UV(b/this.segmentsR,c/this.segmentsT),o=new THREE.UV((b+1)/this.segmentsR,c/this.segmentsT),u=new THREE.UV((b+1)/this.segmentsR,(c+1)/this.segmentsT),v=new THREE.UV(b/this.segmentsR,(c+1)/this.segmentsT);this.faces.push(new THREE.Face4(m,e,f,k));this.faceVertexUvs[0].push([h,o,u,v])}this.computeCentroids();
524 525
this.computeFaceNormals();this.computeVertexNormals()};THREE.TorusKnotGeometry.prototype=new THREE.Geometry;THREE.TorusKnotGeometry.prototype.constructor=THREE.TorusKnotGeometry;THREE.Loader=function(b){this.statusDomElement=(this.showStatus=b)?THREE.Loader.prototype.addStatusElement():null;this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){}};
THREE.Loader.prototype={addStatusElement:function(){var b=document.createElement("div");b.style.position="absolute";b.style.right="0px";b.style.top="0px";b.style.fontSize="0.8em";b.style.textAlign="left";b.style.background="rgba(0,0,0,0.25)";b.style.color="#fff";b.style.width="120px";b.style.padding="0.5em 0.5em 0.5em 0.5em";b.style.zIndex=1E3;b.innerHTML="Loading ...";return b},updateProgress:function(b){var c="Loaded ";c+=b.total?(100*b.loaded/b.total).toFixed(0)+"%":(b.loaded/1E3).toFixed(2)+" KB";
A
alteredq 已提交
526
this.statusDomElement.innerHTML=c},extractUrlbase:function(b){b=b.split("/");b.pop();return b.length<1?".":b.join("/")},init_materials:function(b,c,e){b.materials=[];for(var f=0;f<c.length;++f)b.materials[f]=[THREE.Loader.prototype.createMaterial(c[f],e)]},hasNormals:function(b){var c,e,f=b.materials.length;for(e=0;e<f;e++)if(c=b.materials[e][0],c instanceof THREE.ShaderMaterial)return!0;return!1},createMaterial:function(b,c){function e(b){b=Math.log(b)/Math.LN2;return Math.floor(b)==b}function f(b,
527 528 529 530 531 532
c){var f=new Image;f.onload=function(){if(!e(this.width)||!e(this.height)){var c=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),f=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));b.image.width=c;b.image.height=f;b.image.getContext("2d").drawImage(this,0,0,c,f)}else b.image=this;b.needsUpdate=!0};f.src=c}function m(b,e,h,k,m,n){var o=document.createElement("canvas");b[e]=new THREE.Texture(o);b[e].sourceFile=h;if(k){b[e].repeat.set(k[0],k[1]);if(k[0]!=1)b[e].wrapS=THREE.RepeatWrapping;
if(k[1]!=1)b[e].wrapT=THREE.RepeatWrapping}m&&b[e].offset.set(m[0],m[1]);if(n){k={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(k[n[0]]!==void 0)b[e].wrapS=k[n[0]];if(k[n[1]]!==void 0)b[e].wrapT=k[n[1]]}f(b[e],c+"/"+h)}function k(b){return(b[0]*255<<16)+(b[1]*255<<8)+b[2]*255}var h,n,o;n="MeshLambertMaterial";h={color:15658734,opacity:1,map:null,lightMap:null,normalMap:null,wireframe:b.wireframe};b.shading&&(b.shading=="Phong"?n="MeshPhongMaterial":b.shading=="Basic"&&(n="MeshBasicMaterial"));
if(b.blending)if(b.blending=="Additive")h.blending=THREE.AdditiveBlending;else if(b.blending=="Subtractive")h.blending=THREE.SubtractiveBlending;else if(b.blending=="Multiply")h.blending=THREE.MultiplyBlending;if(b.transparent!==void 0||b.opacity<1)h.transparent=b.transparent;if(b.depthTest!==void 0)h.depthTest=b.depthTest;if(b.vertexColors!==void 0)if(b.vertexColors=="face")h.vertexColors=THREE.FaceColors;else if(b.vertexColors)h.vertexColors=THREE.VertexColors;if(b.colorDiffuse)h.color=k(b.colorDiffuse);
else if(b.DbgColor)h.color=b.DbgColor;if(b.colorSpecular)h.specular=k(b.colorSpecular);if(b.colorAmbient)h.ambient=k(b.colorAmbient);if(b.transparency)h.opacity=b.transparency;if(b.specularCoef)h.shininess=b.specularCoef;b.mapDiffuse&&c&&m(h,"map",b.mapDiffuse,b.mapDiffuseRepeat,b.mapDiffuseOffset,b.mapDiffuseWrap);b.mapLight&&c&&m(h,"lightMap",b.mapLight,b.mapLightRepeat,b.mapLightOffset,b.mapLightWrap);b.mapNormal&&c&&m(h,"normalMap",b.mapNormal,b.mapNormalRepeat,b.mapNormalOffset,b.mapNormalWrap);
b.mapSpecular&&c&&m(h,"specularMap",b.mapSpecular,b.mapSpecularRepeat,b.mapSpecularOffset,b.mapSpecularWrap);if(b.mapNormal){var u=THREE.ShaderUtils.lib.normal,v=THREE.UniformsUtils.clone(u.uniforms),t=h.color;n=h.specular;o=h.ambient;var x=h.shininess;v.tNormal.texture=h.normalMap;if(b.mapNormalFactor)v.uNormalScale.value=b.mapNormalFactor;if(h.map)v.tDiffuse.texture=h.map,v.enableDiffuse.value=!0;if(h.specularMap)v.tSpecular.texture=h.specularMap,v.enableSpecular.value=!0;if(h.lightMap)v.tAO.texture=
h.lightMap,v.enableAO.value=!0;v.uDiffuseColor.value.setHex(t);v.uSpecularColor.value.setHex(n);v.uAmbientColor.value.setHex(o);v.uShininess.value=x;if(h.opacity)v.uOpacity.value=h.opacity;h=new THREE.ShaderMaterial({fragmentShader:u.fragmentShader,vertexShader:u.vertexShader,uniforms:v,lights:!0,fog:!0})}else h=new THREE[n](h);return h},constructor:THREE.Loader};THREE.BinaryLoader=function(b){THREE.Loader.call(this,b)};THREE.BinaryLoader.prototype=new THREE.Loader;
A
alteredq 已提交
533
THREE.BinaryLoader.prototype.constructor=THREE.BinaryLoader;THREE.BinaryLoader.prototype.supr=THREE.Loader.prototype;
534
THREE.BinaryLoader.prototype.load=function(b){var c=b.model,e=b.callback,f=b.texture_path?b.texture_path:THREE.Loader.prototype.extractUrlbase(c),m=b.bin_path?b.bin_path:THREE.Loader.prototype.extractUrlbase(c),b=(new Date).getTime(),c=new Worker(c),k=this.showProgress?THREE.Loader.prototype.updateProgress:null;c.onmessage=function(b){THREE.BinaryLoader.prototype.loadAjaxBuffers(b.data.buffers,b.data.materials,e,m,f,k)};c.onerror=function(b){alert("worker.onerror: "+b.message+"\n"+b.data);b.preventDefault()};
535
c.postMessage(b)};
536 537
THREE.BinaryLoader.prototype.loadAjaxBuffers=function(b,c,e,f,m,k){var h=new XMLHttpRequest,n=f+"/"+b,o=0;h.onreadystatechange=function(){h.readyState==4?h.status==200||h.status==0?THREE.BinaryLoader.prototype.createBinModel(h.responseText,e,m,c):alert("Couldn't load ["+n+"] ["+h.status+"]"):h.readyState==3?k&&(o==0&&(o=h.getResponseHeader("Content-Length")),k({total:o,loaded:h.responseText.length})):h.readyState==2&&(o=h.getResponseHeader("Content-Length"))};h.open("GET",n,!0);h.overrideMimeType("text/plain; charset=x-user-defined");
h.setRequestHeader("Content-Type","text/plain");h.send(null)};
538 539 540 541 542 543 544 545 546 547 548 549 550
THREE.BinaryLoader.prototype.createBinModel=function(b,c,e,f){var m=function(e){function c(b,e){var f=v(b,e),h=v(b,e+1),k=v(b,e+2),m=v(b,e+3),n=(m<<1&255|k>>7)-127;f|=(k&127)<<16|h<<8;if(f==0&&n==-127)return 0;return(1-2*(m>>7))*(1+f*Math.pow(2,-23))*Math.pow(2,n)}function m(b,e){var c=v(b,e),f=v(b,e+1),h=v(b,e+2);return(v(b,e+3)<<24)+(h<<16)+(f<<8)+c}function o(b,e){var c=v(b,e);return(v(b,e+1)<<8)+c}function u(b,e){var c=v(b,e);return c>127?c-256:c}function v(b,e){return b.charCodeAt(e)&255}function t(e){var c,
f,h;c=m(b,e);f=m(b,e+R);h=m(b,e+H);e=o(b,e+J);D.faces.push(new THREE.Face3(c,f,h,null,null,D.materials[e]))}function x(e){var c,f,h,k,p,t;c=m(b,e);f=m(b,e+R);h=m(b,e+H);k=o(b,e+J);p=m(b,e+I);t=m(b,e+X);e=m(b,e+E);k=D.materials[k];var u=G[t*3],w=G[t*3+1];t=G[t*3+2];var v=G[e*3],x=G[e*3+1],e=G[e*3+2];D.faces.push(new THREE.Face3(c,f,h,[new THREE.Vector3(G[p*3],G[p*3+1],G[p*3+2]),new THREE.Vector3(u,w,t),new THREE.Vector3(v,x,e)],null,k))}function w(e){var c,f,h,k;c=m(b,e);f=m(b,e+O);h=m(b,e+P);k=m(b,
e+U);e=o(b,e+V);D.faces.push(new THREE.Face4(c,f,h,k,null,null,D.materials[e]))}function y(e){var c,f,h,k,t,u,w,v;c=m(b,e);f=m(b,e+O);h=m(b,e+P);k=m(b,e+U);t=o(b,e+V);u=m(b,e+p);w=m(b,e+ea);v=m(b,e+S);e=m(b,e+ka);t=D.materials[t];var x=G[w*3],L=G[w*3+1];w=G[w*3+2];var y=G[v*3],W=G[v*3+1];v=G[v*3+2];var z=G[e*3],A=G[e*3+1],e=G[e*3+2];D.faces.push(new THREE.Face4(c,f,h,k,[new THREE.Vector3(G[u*3],G[u*3+1],G[u*3+2]),new THREE.Vector3(x,L,w),new THREE.Vector3(y,W,v),new THREE.Vector3(z,A,e)],null,t))}
function A(e){var c,f,h,k;c=m(b,e);f=m(b,e+$);h=m(b,e+ia);e=N[c*2];k=N[c*2+1];c=N[f*2];var p=D.faceVertexUvs[0];f=N[f*2+1];var o=N[h*2];h=N[h*2+1];var t=[];t.push(new THREE.UV(e,k));t.push(new THREE.UV(c,f));t.push(new THREE.UV(o,h));p.push(t)}function z(e){var c,f,h,k,p,o;c=m(b,e);f=m(b,e+ca);h=m(b,e+ma);k=m(b,e+fa);e=N[c*2];p=N[c*2+1];c=N[f*2];o=N[f*2+1];f=N[h*2];var t=D.faceVertexUvs[0];h=N[h*2+1];var u=N[k*2];k=N[k*2+1];var w=[];w.push(new THREE.UV(e,p));w.push(new THREE.UV(c,o));w.push(new THREE.UV(f,
h));w.push(new THREE.UV(u,k));t.push(w)}var D=this,C=0,F,G=[],N=[],R,H,J,I,X,E,O,P,U,V,p,ea,S,ka,$,ia,ca,ma,fa,da,T,Y,ga,ja,sa;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(D,f,e);F={signature:b.substr(C,8),header_bytes:v(b,C+8),vertex_coordinate_bytes:v(b,C+9),normal_coordinate_bytes:v(b,C+10),uv_coordinate_bytes:v(b,C+11),vertex_index_bytes:v(b,C+12),normal_index_bytes:v(b,C+13),uv_index_bytes:v(b,C+14),material_index_bytes:v(b,C+15),nvertices:m(b,C+16),nnormals:m(b,C+16+4),nuvs:m(b,
C+16+8),ntri_flat:m(b,C+16+12),ntri_smooth:m(b,C+16+16),ntri_flat_uv:m(b,C+16+20),ntri_smooth_uv:m(b,C+16+24),nquad_flat:m(b,C+16+28),nquad_smooth:m(b,C+16+32),nquad_flat_uv:m(b,C+16+36),nquad_smooth_uv:m(b,C+16+40)};C+=F.header_bytes;R=F.vertex_index_bytes;H=F.vertex_index_bytes*2;J=F.vertex_index_bytes*3;I=F.vertex_index_bytes*3+F.material_index_bytes;X=F.vertex_index_bytes*3+F.material_index_bytes+F.normal_index_bytes;E=F.vertex_index_bytes*3+F.material_index_bytes+F.normal_index_bytes*2;O=F.vertex_index_bytes;
P=F.vertex_index_bytes*2;U=F.vertex_index_bytes*3;V=F.vertex_index_bytes*4;p=F.vertex_index_bytes*4+F.material_index_bytes;ea=F.vertex_index_bytes*4+F.material_index_bytes+F.normal_index_bytes;S=F.vertex_index_bytes*4+F.material_index_bytes+F.normal_index_bytes*2;ka=F.vertex_index_bytes*4+F.material_index_bytes+F.normal_index_bytes*3;$=F.uv_index_bytes;ia=F.uv_index_bytes*2;ca=F.uv_index_bytes;ma=F.uv_index_bytes*2;fa=F.uv_index_bytes*3;e=F.vertex_index_bytes*3+F.material_index_bytes;sa=F.vertex_index_bytes*
4+F.material_index_bytes;da=F.ntri_flat*e;T=F.ntri_smooth*(e+F.normal_index_bytes*3);Y=F.ntri_flat_uv*(e+F.uv_index_bytes*3);ga=F.ntri_smooth_uv*(e+F.normal_index_bytes*3+F.uv_index_bytes*3);ja=F.nquad_flat*sa;e=F.nquad_smooth*(sa+F.normal_index_bytes*4);sa=F.nquad_flat_uv*(sa+F.uv_index_bytes*4);C+=function(e){for(var f,k,m,n=F.vertex_coordinate_bytes*3,p=e+F.nvertices*n;e<p;e+=n)f=c(b,e),k=c(b,e+F.vertex_coordinate_bytes),m=c(b,e+F.vertex_coordinate_bytes*2),D.vertices.push(new THREE.Vertex(new THREE.Vector3(f,
k,m)));return F.nvertices*n}(C);C+=function(e){for(var c,f,h,k=F.normal_coordinate_bytes*3,m=e+F.nnormals*k;e<m;e+=k)c=u(b,e),f=u(b,e+F.normal_coordinate_bytes),h=u(b,e+F.normal_coordinate_bytes*2),G.push(c/127,f/127,h/127);return F.nnormals*k}(C);C+=function(e){for(var f,k,m=F.uv_coordinate_bytes*2,n=e+F.nuvs*m;e<n;e+=m)f=c(b,e),k=c(b,e+F.uv_coordinate_bytes),N.push(f,k);return F.nuvs*m}(C);da=C+da;T=da+T;Y=T+Y;ga=Y+ga;ja=ga+ja;e=ja+e;sa=e+sa;(function(b){var e,c=F.vertex_index_bytes*3+F.material_index_bytes,
f=c+F.uv_index_bytes*3,h=b+F.ntri_flat_uv*f;for(e=b;e<h;e+=f)t(e),A(e+c);return h-b})(T);(function(b){var e,c=F.vertex_index_bytes*3+F.material_index_bytes+F.normal_index_bytes*3,f=c+F.uv_index_bytes*3,h=b+F.ntri_smooth_uv*f;for(e=b;e<h;e+=f)x(e),A(e+c);return h-b})(Y);(function(b){var e,c=F.vertex_index_bytes*4+F.material_index_bytes,f=c+F.uv_index_bytes*4,h=b+F.nquad_flat_uv*f;for(e=b;e<h;e+=f)w(e),z(e+c);return h-b})(e);(function(b){var e,c=F.vertex_index_bytes*4+F.material_index_bytes+F.normal_index_bytes*
4,f=c+F.uv_index_bytes*4,h=b+F.nquad_smooth_uv*f;for(e=b;e<h;e+=f)y(e),z(e+c);return h-b})(sa);(function(b){var e,c=F.vertex_index_bytes*3+F.material_index_bytes,f=b+F.ntri_flat*c;for(e=b;e<f;e+=c)t(e);return f-b})(C);(function(b){var e,c=F.vertex_index_bytes*3+F.material_index_bytes+F.normal_index_bytes*3,f=b+F.ntri_smooth*c;for(e=b;e<f;e+=c)x(e);return f-b})(da);(function(b){var e,c=F.vertex_index_bytes*4+F.material_index_bytes,f=b+F.nquad_flat*c;for(e=b;e<f;e+=c)w(e);return f-b})(ga);(function(b){var e,
c=F.vertex_index_bytes*4+F.material_index_bytes+F.normal_index_bytes*4,f=b+F.nquad_smooth*c;for(e=b;e<f;e+=c)y(e);return f-b})(ja);this.computeCentroids();this.computeFaceNormals();THREE.Loader.prototype.hasNormals(this)&&this.computeTangents()};m.prototype=new THREE.Geometry;m.prototype.constructor=m;c(new m(e))};
THREE.ColladaLoader=function(){function b(b,e,c){for(var b=da.evaluate(b,da,S,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),f={},h=b.iterateNext(),k=0;h;){h=(new e).parse(h);if(h.id.length==0)h.id=c+k++;f[h.id]=h;h=b.iterateNext()}return f}function c(){var b=1E6,e=-b,c=0,f;for(f in M)for(var h=M[f],k=0;k<h.sampler.length;k++){var m=h.sampler[k];m.create();b=Math.min(b,m.startTime);e=Math.max(e,m.endTime);c=Math.max(c,m.input.length)}return{start:b,end:e,frames:c}}function e(b,c,f,h){b.world=b.world||
551 552
new THREE.Matrix4;b.world.copy(b.matrix);if(b.channels&&b.channels.length){var k=b.channels[0].sampler.output[f];k instanceof THREE.Matrix4&&b.world.copy(k)}h&&b.world.multiply(h,b.world);c.push(b);for(h=0;h<b.nodes.length;h++)e(b.nodes[h],c,f,b.world)}function f(b,f,h){var k=la[f.url];if(!k||!k.skin)console.log("could not find skin controller!");else if(!f.skeleton||!f.skeleton.length)console.log("could not find the skeleton for the skin!");else{var m=c(),f=Y.getChildById(f.skeleton[0],!0)||Y.getChildBySid(f.skeleton[0],
!0),n,p,o,t,u=new THREE.Vector3,w;for(n=0;n<b.vertices.length;n++)k.skin.bindShapeMatrix.multiplyVector3(b.vertices[n].position);for(h=0;h<m.frames;h++){var v=[],x=[];for(n=0;n<b.vertices.length;n++)x.push(new THREE.Vertex(new THREE.Vector3));e(f,v,h);n=v;p=k.skin;for(t=0;t<n.length;t++){o=n[t];w=-1;for(var y=0;y<p.joints.length;y++)if(o.sid==p.joints[y]){w=y;break}if(w>=0){y=p.invBindMatrices[w];o.invBindMatrix=y;o.skinningMatrix=new THREE.Matrix4;o.skinningMatrix.multiply(o.world,y);o.weights=[];
553 554 555 556 557
for(y=0;y<p.weights.length;y++)for(var z=0;z<p.weights[y].length;z++){var A=p.weights[y][z];A.joint==w&&o.weights.push(A)}}else throw"could not find joint!";}for(n=0;n<v.length;n++)for(p=0;p<v[n].weights.length;p++)o=v[n].weights[p],t=o.index,o=o.weight,w=b.vertices[t],t=x[t],u.x=w.position.x,u.y=w.position.y,u.z=w.position.z,v[n].skinningMatrix.multiplyVector3(u),t.position.x+=u.x*o,t.position.y+=u.y*o,t.position.z+=u.z*o;b.morphTargets.push({name:"target_"+h,vertices:x})}}}function m(b){var e=new THREE.Object3D,
c,h,k;e.name=b.id||"";e.matrixAutoUpdate=!1;e.matrix=b.matrix;for(k=0;k<b.controllers.length;k++){var n=la[b.controllers[k].url];switch(n.type){case "skin":if(pa[n.skin.source]){var o=new y;o.url=n.skin.source;o.instance_material=b.controllers[k].instance_material;b.geometries.push(o);c=b.controllers[k]}else if(la[n.skin.source]&&(h=n=la[n.skin.source],n.morph&&pa[n.morph.source]))o=new y,o.url=n.morph.source,o.instance_material=b.controllers[k].instance_material,b.geometries.push(o);break;case "morph":if(pa[n.morph.source])o=
new y,o.url=n.morph.source,o.instance_material=b.controllers[k].instance_material,b.geometries.push(o),h=b.controllers[k];console.log("DAE: morph-controller partially supported.")}}for(k=0;k<b.geometries.length;k++){var n=b.geometries[k],o=n.instance_material,n=pa[n.url],p={},t=0,u;if(n&&n.mesh&&n.mesh.primitives){if(e.name.length==0)e.name=n.id;if(o)for(j=0;j<o.length;j++){u=o[j];var w=wa[qa[u.target].instance_effect.url].shader;w.material.opacity=!w.material.opacity?1:w.material.opacity;u=p[u.symbol]=
w.material;t++}o=u||new THREE.MeshLambertMaterial({color:14540253,shading:THREE.FlatShading});n=n.mesh.geometry3js;if(t>1){o=new THREE.MeshFaceMaterial;for(j=0;j<n.faces.length;j++)t=n.faces[j],t.materials=[p[t.daeMaterial]]}if(c!==void 0)f(n,c),o.morphTargets=!0,o=new THREE.SkinnedMesh(n,o),o.skeleton=c.skeleton,o.skinController=la[c.url],o.skinInstanceController=c,o.name="skin_"+Ba.length,Ba.push(o);else if(h!==void 0){p=n;t=h instanceof x?la[h.url]:h;if(!t||!t.morph)console.log("could not find morph controller!");
else{t=t.morph;for(w=0;w<t.targets.length;w++){var v=pa[t.targets[w]];if(v.mesh&&v.mesh.primitives&&v.mesh.primitives.length)v=v.mesh.primitives[0].geometry,v.vertices.length===p.vertices.length&&p.morphTargets.push({name:"target_1",vertices:v.vertices})}p.morphTargets.push({name:"target_Z",vertices:p.vertices})}o.morphTargets=!0;o=new THREE.Mesh(n,o);o.name="morph_"+za.length;za.push(o)}else o=new THREE.Mesh(n,o);e.add(o)}}for(k=0;k<b.nodes.length;k++)e.add(m(b.nodes[k],b));return e}function k(){this.init_from=
558
this.id=""}function h(){this.type=this.name=this.id="";this.morph=this.skin=null}function n(){this.weights=this.targets=this.source=this.method=null}function o(){this.source="";this.bindShapeMatrix=null;this.invBindMatrices=[];this.joints=[];this.weights=[]}function u(){this.name=this.id="";this.nodes=[];this.scene=new THREE.Object3D}function v(){this.sid=this.name=this.id="";this.nodes=[];this.controllers=[];this.transforms=[];this.geometries=[];this.channels=[];this.matrix=new THREE.Matrix4}function t(){this.type=
559 560
this.sid="";this.data=[];this.matrix=new THREE.Matrix4}function x(){this.url="";this.skeleton=[];this.instance_material=[]}function w(){this.target=this.symbol=""}function y(){this.url="";this.instance_material=[]}function A(){this.id="";this.mesh=null}function z(b){this.geometry=b.id;this.primitives=[];this.geometry3js=this.vertices=null}function D(){}function C(){this.material="";this.count=0;this.inputs=[];this.vcount=null;this.p=[];this.geometry=new THREE.Geometry}function F(){this.source="";
this.stride=this.count=0;this.params=[]}function G(){this.input={}}function N(){this.semantic="";this.offset=0;this.source="";this.set=0}function R(b){this.id=b;this.type=null}function H(){this.name=this.id="";this.instance_effect=null}function J(){this.color=new THREE.Color(0);this.color.setRGB(Math.random(),Math.random(),Math.random());this.color.a=1;this.texcoord=this.texture=null}function I(b,e){this.type=b;this.effect=e;this.material=null}function X(b){this.effect=b;this.format=this.init_from=
561
null}function E(b){this.effect=b;this.mipfilter=this.magfilter=this.minfilter=this.wrap_t=this.wrap_s=this.source=null}function O(){this.name=this.id="";this.sampler=this.surface=this.shader=null}function P(){this.url=""}function U(){this.name=this.id="";this.source={};this.sampler=[];this.channel=[]}function V(b){this.animation=b;this.target=this.source="";this.member=this.arrIndices=this.arrSyntax=this.dotSyntax=this.sid=null}function p(b){this.id="";this.animation=b;this.inputs=[];this.endTime=
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
this.startTime=this.interpolation=this.output=this.input=null;this.duration=0}function ea(b){var e=b.getAttribute("id");if(ja[e]!=void 0)return ja[e];ja[e]=(new R(e)).parse(b);return ja[e]}function S(b){if(b=="dae")return"http://www.collada.org/2005/11/COLLADASchema";return null}function ka(b){for(var b=ia(b),e=[],c=0;c<b.length;c++)e.push(parseFloat(b[c]));return e}function $(b){for(var b=ia(b),e=[],c=0;c<b.length;c++)e.push(parseInt(b[c],10));return e}function ia(b){return b.replace(/^\s+/,"").replace(/\s+$/,
"").split(/\s+/)}function ca(b,e,c){return b.hasAttribute(e)?parseInt(b.getAttribute(e),10):c}function ma(b,e){if(b===void 0){for(var c="0.";c.length<e+2;)c+="0";return c}e=e||2;c=b.toString().split(".");for(c[1]=c.length>1?c[1].substr(0,e):"0";c[1].length<e;)c[1]+="0";return c.join(".")}function fa(b,e){var c="";c+=ma(b.x,e)+",";c+=ma(b.y,e)+",";c+=ma(b.z,e);return c}var da=null,T=null,Y,ga=null,ja={},sa={},M={},la={},pa={},qa={},wa={},ua,Da,za,Ba,Fa=THREE.SmoothShading;k.prototype.parse=function(b){this.id=
b.getAttribute("id");for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeName=="init_from")this.init_from=c.textContent}return this};h.prototype.parse=function(b){this.id=b.getAttribute("id");this.name=b.getAttribute("name");this.type="none";for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];switch(c.nodeName){case "skin":this.skin=(new o).parse(c);this.type=c.nodeName;break;case "morph":this.morph=(new n).parse(c),this.type=c.nodeName}}return this};n.prototype.parse=function(b){var e=
{},c=[],f;this.method=b.getAttribute("method");this.source=b.getAttribute("source").replace(/^#/,"");for(f=0;f<b.childNodes.length;f++){var h=b.childNodes[f];if(h.nodeType==1)switch(h.nodeName){case "source":h=(new R).parse(h);e[h.id]=h;break;case "targets":c=this.parseInputs(h);break;default:console.log(h.nodeName)}}for(f=0;f<c.length;f++)switch(b=c[f],h=e[b.source],b.semantic){case "MORPH_TARGET":this.targets=h.read();break;case "MORPH_WEIGHT":this.weights=h.read()}return this};n.prototype.parseInputs=
function(b){for(var e=[],c=0;c<b.childNodes.length;c++){var f=b.childNodes[c];if(f.nodeType==1)switch(f.nodeName){case "input":e.push((new N).parse(f))}}return e};o.prototype.parse=function(b){var e={},c,f;this.source=b.getAttribute("source").replace(/^#/,"");this.invBindMatrices=[];this.joints=[];this.weights=[];for(var h=0;h<b.childNodes.length;h++){var k=b.childNodes[h];if(k.nodeType==1)switch(k.nodeName){case "bind_shape_matrix":k=ka(k.textContent);this.bindShapeMatrix=new THREE.Matrix4;this.bindShapeMatrix.set(k[0],
k[1],k[2],k[3],k[4],k[5],k[6],k[7],k[8],k[9],k[10],k[11],k[12],k[13],k[14],k[15]);break;case "source":k=(new R).parse(k);e[k.id]=k;break;case "joints":c=k;break;case "vertex_weights":f=k;break;default:console.log(k.nodeName)}}this.parseJoints(c,e);this.parseWeights(f,e);return this};o.prototype.parseJoints=function(b,e){for(var c=0;c<b.childNodes.length;c++){var f=b.childNodes[c];if(f.nodeType==1)switch(f.nodeName){case "input":var f=(new N).parse(f),h=e[f.source];if(f.semantic=="JOINT")this.joints=
h.read();else if(f.semantic=="INV_BIND_MATRIX")this.invBindMatrices=h.read()}}};o.prototype.parseWeights=function(b,e){for(var c,f,h=[],k=0;k<b.childNodes.length;k++){var m=b.childNodes[k];if(m.nodeType==1)switch(m.nodeName){case "input":h.push((new N).parse(m));break;case "v":c=$(m.textContent);break;case "vcount":f=$(m.textContent)}}for(k=m=0;k<f.length;k++){for(var n=f[k],o=[],p=0;p<n;p++){for(var t={},u=0;u<h.length;u++){var w=h[u],v=c[m+w.offset];switch(w.semantic){case "JOINT":t.joint=v;break;
case "WEIGHT":t.weight=e[w.source].data[v]}}o.push(t);m+=h.length}for(p=0;p<o.length;p++)o[p].index=k;this.weights.push(o)}};u.prototype.getChildById=function(b,e){for(var c=0;c<this.nodes.length;c++){var f=this.nodes[c].getChildById(b,e);if(f)return f}return null};u.prototype.getChildBySid=function(b,e){for(var c=0;c<this.nodes.length;c++){var f=this.nodes[c].getChildBySid(b,e);if(f)return f}return null};u.prototype.parse=function(b){this.id=b.getAttribute("id");this.name=b.getAttribute("name");
this.nodes=[];for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "node":this.nodes.push((new v).parse(c))}}return this};v.prototype.getChannelForTransform=function(b){for(var e=0;e<this.channels.length;e++){var c=this.channels[e],f=c.target.split("/");f.shift();var h=f.shift(),k=h.indexOf(".")>=0,m=h.indexOf("(")>=0,n;if(k)f=h.split("."),h=f.shift(),f.shift();else if(m){n=h.split("(");h=n.shift();for(f=0;f<n.length;f++)n[f]=parseInt(n[f].replace(/\)/,
""))}if(h==b)return c.info={sid:h,dotSyntax:k,arrSyntax:m,arrIndices:n},c}return null};v.prototype.getChildById=function(b,e){if(this.id==b)return this;if(e)for(var c=0;c<this.nodes.length;c++){var f=this.nodes[c].getChildById(b,e);if(f)return f}return null};v.prototype.getChildBySid=function(b,e){if(this.sid==b)return this;if(e)for(var c=0;c<this.nodes.length;c++){var f=this.nodes[c].getChildBySid(b,e);if(f)return f}return null};v.prototype.getTransformBySid=function(b){for(var e=0;e<this.transforms.length;e++)if(this.transforms[e].sid==
b)return this.transforms[e];return null};v.prototype.parse=function(b){var e;this.id=b.getAttribute("id");this.sid=b.getAttribute("sid");this.name=b.getAttribute("name");this.type=b.getAttribute("type");this.type=this.type=="JOINT"?this.type:"NODE";this.nodes=[];this.transforms=[];this.geometries=[];this.controllers=[];this.matrix=new THREE.Matrix4;for(var c=0;c<b.childNodes.length;c++)if(e=b.childNodes[c],e.nodeType==1)switch(e.nodeName){case "node":this.nodes.push((new v).parse(e));break;case "instance_camera":break;
case "instance_controller":this.controllers.push((new x).parse(e));break;case "instance_geometry":this.geometries.push((new y).parse(e));break;case "instance_light":break;case "instance_node":e=e.getAttribute("url").replace(/^#/,"");(e=da.evaluate(".//dae:library_nodes//dae:node[@id='"+e+"']",da,S,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null).iterateNext())&&this.nodes.push((new v).parse(e));break;case "rotate":case "translate":case "scale":case "matrix":case "lookat":case "skew":this.transforms.push((new t).parse(e));
break;case "extra":break;default:console.log(e.nodeName)}b=[];c=1E6;e=-1E6;for(var f in M)for(var h=M[f],k=0;k<h.channel.length;k++){var m=h.channel[k],n=h.sampler[k];f=m.target.split("/")[0];if(f==this.id)n.create(),m.sampler=n,c=Math.min(c,n.startTime),e=Math.max(e,n.endTime),b.push(m)}if(b.length)this.startTime=c,this.endTime=e;if((this.channels=b)&&this.channels.length){f=1E7;for(i=0;i<this.channels.length;i++){b=this.channels[i].sampler;for(c=0;c<b.input.length-1;c++)f=Math.min(f,b.input[c+1]-
b.input[c])}c=[];for(b=this.startTime;b<this.endTime;b+=f){e=b;for(var h={},o=k=void 0,k=0;k<this.channels.length;k++)o=this.channels[k],h[o.sid]=o;m=new THREE.Matrix4;for(k=0;k<this.transforms.length;k++)if(n=this.transforms[k],o=h[n.sid],o!==void 0){for(var p=o.sampler,u,o=0;o<p.input.length-1;o++)if(p.input[o+1]>e){u=p.output[o];break}m=u!==void 0?u instanceof THREE.Matrix4?m.multiply(m,u):m.multiply(m,n.matrix):m.multiply(m,n.matrix)}else m=m.multiply(m,n.matrix);e=m;c.push({time:b,pos:[e.n14,
e.n24,e.n34],rotq:[0,0,0,1],scl:[1,1,1]})}this.keys=c}this.updateMatrix();return this};v.prototype.updateMatrix=function(){this.matrix.identity();for(var b=0;b<this.transforms.length;b++)this.matrix.multiply(this.matrix,this.transforms[b].matrix)};t.prototype.parse=function(b){this.sid=b.getAttribute("sid");this.type=b.nodeName;this.data=ka(b.textContent);this.updateMatrix();return this};t.prototype.updateMatrix=function(){var b=0;this.matrix.identity();switch(this.type){case "matrix":this.matrix.set(this.data[0],
M
Mr.doob 已提交
577
this.data[1],this.data[2],this.data[3],this.data[4],this.data[5],this.data[6],this.data[7],this.data[8],this.data[9],this.data[10],this.data[11],this.data[12],this.data[13],this.data[14],this.data[15]);break;case "translate":this.matrix.setTranslation(this.data[0],this.data[1],this.data[2]);break;case "rotate":b=this.data[3]*(Math.PI/180);this.matrix.setRotationAxis(new THREE.Vector3(this.data[0],this.data[1],this.data[2]),b);break;case "scale":this.matrix.setScale(this.data[0],this.data[1],this.data[2])}return this.matrix};
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
x.prototype.parse=function(b){this.url=b.getAttribute("url").replace(/^#/,"");this.skeleton=[];this.instance_material=[];for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "skeleton":this.skeleton.push(c.textContent.replace(/^#/,""));break;case "bind_material":if(c=da.evaluate(".//dae:instance_material",c,S,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null))for(var f=c.iterateNext();f;)this.instance_material.push((new w).parse(f)),f=c.iterateNext()}}return this};
w.prototype.parse=function(b){this.symbol=b.getAttribute("symbol");this.target=b.getAttribute("target").replace(/^#/,"");return this};y.prototype.parse=function(b){this.url=b.getAttribute("url").replace(/^#/,"");this.instance_material=[];for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1&&c.nodeName=="bind_material"){if(b=da.evaluate(".//dae:instance_material",c,S,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null))for(e=b.iterateNext();e;)this.instance_material.push((new w).parse(e)),
e=b.iterateNext();break}}return this};A.prototype.parse=function(b){this.id=b.getAttribute("id");for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];switch(c.nodeName){case "mesh":this.mesh=(new z(this)).parse(c)}}return this};z.prototype.parse=function(b){function e(b,c){var f=fa(b.position);h[f]===void 0&&(h[f]={v:b,index:c});return h[f]}this.primitives=[];var c;for(c=0;c<b.childNodes.length;c++){var f=b.childNodes[c];switch(f.nodeName){case "source":ea(f);break;case "vertices":this.vertices=
(new G).parse(f);break;case "triangles":this.primitives.push((new C).parse(f));break;case "polygons":console.warn("polygon holes not yet supported!");case "polylist":this.primitives.push((new D).parse(f))}}var h={};this.geometry3js=new THREE.Geometry;f=ja[this.vertices.input.POSITION.source].data;for(b=c=0;c<f.length;c+=3,b++){var k=new THREE.Vertex(new THREE.Vector3(f[c],f[c+1],f[c+2]));e(k,b);this.geometry3js.vertices.push(k)}for(c=0;c<this.primitives.length;c++)primitive=this.primitives[c],primitive.setVertices(this.vertices),
this.handlePrimitive(primitive,this.geometry3js,h);this.geometry3js.computeCentroids();this.geometry3js.computeFaceNormals();this.geometry3js.computeVertexNormals();this.geometry3js.computeBoundingBox();return this};z.prototype.handlePrimitive=function(b,e,c){var f=0,h,k,m=b.p,n=b.inputs,o,p,t,u=0,w=3,v=[];for(h=0;h<n.length;h++)switch(o=n[h],o.semantic){case "TEXCOORD":v.push(o.set)}for(;f<m.length;){var x=[],y=[],z={},A=[];b.vcount&&(w=b.vcount[u++]);for(h=0;h<w;h++)for(k=0;k<n.length;k++)switch(o=
n[k],source=ja[o.source],p=m[f+h*n.length+o.offset],numParams=source.accessor.params.length,t=p*numParams,o.semantic){case "VERTEX":o=fa(e.vertices[p].position);x.push(c[o].index);break;case "NORMAL":y.push(new THREE.Vector3(source.data[t],source.data[t+1],source.data[t+2]));break;case "TEXCOORD":z[o.set]===void 0&&(z[o.set]=[]);z[o.set].push(new THREE.UV(source.data[t],source.data[t+1]));break;case "COLOR":A.push((new THREE.Color).setRGB(source.data[t],source.data[t+1],source.data[t+2]))}var D;w==
3?D=new THREE.Face3(x[0],x[1],x[2],[y[0],y[1],y[2]],A.length?A:new THREE.Color):w==4&&(D=new THREE.Face4(x[0],x[1],x[2],x[3],[y[0],y[1],y[2],y[3]],A.length?A:new THREE.Color));D.daeMaterial=b.material;e.faces.push(D);for(k=0;k<v.length;k++)h=z[v[k]],e.faceVertexUvs[k].push([h[0],h[1],h[2]]);f+=n.length*w}};D.prototype=new C;D.prototype.constructor=D;C.prototype.setVertices=function(b){for(var e=0;e<this.inputs.length;e++)if(this.inputs[e].source==b.id)this.inputs[e].source=b.input.POSITION.source};
C.prototype.parse=function(b){this.inputs=[];this.material=b.getAttribute("material");this.count=ca(b,"count",0);for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];switch(c.nodeName){case "input":this.inputs.push((new N).parse(b.childNodes[e]));break;case "vcount":this.vcount=$(c.textContent);break;case "p":this.p=$(c.textContent)}}return this};F.prototype.parse=function(b){this.params=[];this.source=b.getAttribute("source");this.count=ca(b,"count",0);this.stride=ca(b,"stride",0);for(var e=
0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeName=="param"){var f={};f.name=c.getAttribute("name");f.type=c.getAttribute("type");this.params.push(f)}}return this};G.prototype.parse=function(b){this.id=b.getAttribute("id");for(var e=0;e<b.childNodes.length;e++)b.childNodes[e].nodeName=="input"&&(input=(new N).parse(b.childNodes[e]),this.input[input.semantic]=input);return this};N.prototype.parse=function(b){this.semantic=b.getAttribute("semantic");this.source=b.getAttribute("source").replace(/^#/,
"");this.set=ca(b,"set",-1);this.offset=ca(b,"offset",0);if(this.semantic=="TEXCOORD"&&this.set<0)this.set=0;return this};R.prototype.parse=function(b){this.id=b.getAttribute("id");for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];switch(c.nodeName){case "bool_array":for(var f=ia(c.textContent),h=[],k=0;k<f.length;k++)h.push(f[k]=="true"||f[k]=="1"?!0:!1);this.data=h;this.type=c.nodeName;break;case "float_array":this.data=ka(c.textContent);this.type=c.nodeName;break;case "int_array":this.data=
$(c.textContent);this.type=c.nodeName;break;case "IDREF_array":case "Name_array":this.data=ia(c.textContent);this.type=c.nodeName;break;case "technique_common":for(f=0;f<c.childNodes.length;f++)if(c.childNodes[f].nodeName=="accessor"){this.accessor=(new F).parse(c.childNodes[f]);break}}}return this};R.prototype.read=function(){var b=[],e=this.accessor.params[0];switch(e.type){case "IDREF":case "Name":case "name":case "float":return this.data;case "float4x4":for(e=0;e<this.data.length;e+=16){var c=
this.data.slice(e,e+16),f=new THREE.Matrix4;f.set(c[0],c[1],c[2],c[3],c[4],c[5],c[6],c[7],c[8],c[9],c[10],c[11],c[12],c[13],c[14],c[15]);b.push(f)}break;default:console.log("Dae::Source:read dont know how to read "+e.type)}return b};H.prototype.parse=function(b){this.id=b.getAttribute("id");this.name=b.getAttribute("name");for(var e=0;e<b.childNodes.length;e++)if(b.childNodes[e].nodeName=="instance_effect"){this.instance_effect=(new P).parse(b.childNodes[e]);break}return this};J.prototype.isColor=
function(){return this.texture==null};J.prototype.isTexture=function(){return this.texture!=null};J.prototype.parse=function(b){for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "color":c=ka(c.textContent);this.color=new THREE.Color(0);this.color.setRGB(c[0],c[1],c[2]);this.color.a=c[3];break;case "texture":this.texture=c.getAttribute("texture"),this.texcoord=c.getAttribute("texcoord")}}return this};I.prototype.parse=function(b){for(var e=0;e<b.childNodes.length;e++){var c=
b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "ambient":case "emission":case "diffuse":case "specular":case "transparent":this[c.nodeName]=(new J).parse(c);break;case "shininess":case "reflectivity":case "transparency":var f;f=da.evaluate(".//dae:float",c,S,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);for(var h=f.iterateNext(),k=[];h;)k.push(h),h=f.iterateNext();f=k;f.length>0&&(this[c.nodeName]=parseFloat(f[0].textContent))}}this.create();return this};I.prototype.create=function(){var b=
{},e=this.transparency!==void 0&&this.transparency<1,c;for(c in this)switch(c){case "ambient":case "emission":case "diffuse":case "specular":var f=this[c];if(f instanceof J)if(f.isTexture()){if(this.effect.sampler&&this.effect.surface&&this.effect.sampler.source==this.effect.surface.sid&&(f=sa[this.effect.surface.init_from]))b.map=THREE.ImageUtils.loadTexture(Da+f.init_from),b.map.wrapS=THREE.RepeatWrapping,b.map.wrapT=THREE.RepeatWrapping,b.map.repeat.x=1,b.map.repeat.y=-1}else c=="diffuse"?b.color=
f.color.getHex():e||(b[c]=f.color.getHex());break;case "shininess":case "reflectivity":b[c]=this[c];break;case "transparency":if(e)b.transparent=!0,b.opacity=this[c],e=!0}b.shading=Fa;return this.material=new THREE.MeshLambertMaterial(b)};X.prototype.parse=function(b){for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "init_from":this.init_from=c.textContent;break;case "format":this.format=c.textContent;break;default:console.log("unhandled Surface prop: "+
c.nodeName)}}return this};E.prototype.parse=function(b){for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "source":this.source=c.textContent;break;case "minfilter":this.minfilter=c.textContent;break;case "magfilter":this.magfilter=c.textContent;break;case "mipfilter":this.mipfilter=c.textContent;break;case "wrap_s":this.wrap_s=c.textContent;break;case "wrap_t":this.wrap_t=c.textContent;break;default:console.log("unhandled Sampler2D prop: "+c.nodeName)}}return this};
O.prototype.create=function(){if(this.shader==null)return null};O.prototype.parse=function(b){this.id=b.getAttribute("id");this.name=b.getAttribute("name");this.shader=null;for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "profile_COMMON":this.parseTechnique(this.parseProfileCOMMON(c))}}return this};O.prototype.parseNewparam=function(b){for(var e=b.getAttribute("sid"),c=0;c<b.childNodes.length;c++){var f=b.childNodes[c];if(f.nodeType==1)switch(f.nodeName){case "surface":this.surface=
(new X(this)).parse(f);this.surface.sid=e;break;case "sampler2D":this.sampler=(new E(this)).parse(f);this.sampler.sid=e;break;case "extra":break;default:console.log(f.nodeName)}}};O.prototype.parseProfileCOMMON=function(b){for(var e,c=0;c<b.childNodes.length;c++){var f=b.childNodes[c];if(f.nodeType==1)switch(f.nodeName){case "profile_COMMON":this.parseProfileCOMMON(f);break;case "technique":e=f;break;case "newparam":this.parseNewparam(f);break;case "extra":break;default:console.log(f.nodeName)}}return e};
O.prototype.parseTechnique=function(b){for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "lambert":case "blinn":case "phong":this.shader=(new I(c.nodeName,this)).parse(c)}}};P.prototype.parse=function(b){this.url=b.getAttribute("url").replace(/^#/,"");return this};U.prototype.parse=function(b){this.id=b.getAttribute("id");this.name=b.getAttribute("name");this.source={};for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "source":c=
(new R).parse(c);this.source[c.id]=c;break;case "sampler":this.sampler.push((new p(this)).parse(c));break;case "channel":this.channel.push((new V(this)).parse(c))}}return this};V.prototype.parse=function(b){this.source=b.getAttribute("source").replace(/^#/,"");this.target=b.getAttribute("target");var e=this.target.split("/");e.shift();var b=e.shift(),c=b.indexOf(".")>=0,f=b.indexOf("(")>=0,h,k;if(c)e=b.split("."),b=e.shift(),k=e.shift();else if(f){h=b.split("(");b=h.shift();for(e=0;e<h.length;e++)h[e]=
parseInt(h[e].replace(/\)/,""))}this.sid=b;this.dotSyntax=c;this.arrSyntax=f;this.arrIndices=h;this.member=k;return this};p.prototype.parse=function(b){this.id=b.getAttribute("id");this.inputs=[];for(var e=0;e<b.childNodes.length;e++){var c=b.childNodes[e];if(c.nodeType==1)switch(c.nodeName){case "input":this.inputs.push((new N).parse(c))}}return this};p.prototype.create=function(){for(var b=0;b<this.inputs.length;b++){var e=this.inputs[b],c=this.animation.source[e.source];switch(e.semantic){case "INPUT":this.input=
c.read();break;case "OUTPUT":this.output=c.read();break;case "INTERPOLATION":this.interpolation=c.read();break;case "IN_TANGENT":break;case "OUT_TANGENT":break;default:console.log(e.semantic)}}this.duration=this.endTime=this.startTime=0;if(this.input.length){this.startTime=1E8;this.endTime=-1E8;for(b=0;b<this.input.length;b++)this.startTime=Math.min(this.startTime,this.input[b]),this.endTime=Math.max(this.endTime,this.input[b]);this.duration=this.endTime-this.startTime}};return{load:function(e,f){if(document.implementation&&
601 602 603 604
document.implementation.createDocument){document.implementation.createDocument("http://www.collada.org/2005/11/COLLADASchema","COLLADA",null);e+="?rnd="+Math.random();var n=new XMLHttpRequest;n.overrideMimeType&&n.overrideMimeType("text/xml");n.onreadystatechange=function(){if(n.readyState==4&&(n.status==0||n.status==200)){ga=f;var o,p=e;da=n.responseXML;o=ga;p!==void 0&&(p=p.split("/"),p.pop(),Da=p.join("/")+"/");sa=b("//dae:library_images/dae:image",k,"image");qa=b("//dae:library_materials/dae:material",
H,"material");wa=b("//dae:library_effects/dae:effect",O,"effect");pa=b("//dae:library_geometries/dae:geometry",A,"geometry");la=b("//dae:library_controllers/dae:controller",h,"controller");M=b("//dae:library_animations/dae:animation",U,"animation");ua=b(".//dae:library_visual_scenes/dae:visual_scene",u,"visual_scene");za=[];Ba=[];(p=da.evaluate(".//dae:scene/dae:instance_visual_scene",da,S,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null).iterateNext())?(p=p.getAttribute("url").replace(/^#/,""),Y=ua[p]):
Y=null;T=new THREE.Object3D;for(p=0;p<Y.nodes.length;p++)T.add(m(Y.nodes[p]));c();for(var t in M);t={scene:T,morphs:za,skins:Ba,dae:{images:sa,materials:qa,effects:wa,geometries:pa,controllers:la,animations:M,visualScenes:ua,scene:Y}};o&&o(t)}};n.open("GET",e,!0);n.send(null)}else alert("Don't know how to parse XML!")},setPreferredShading:function(b){Fa=b},applySkin:f,geometries:pa}};THREE.JSONLoader=function(b){THREE.Loader.call(this,b)};THREE.JSONLoader.prototype=new THREE.Loader;
THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;THREE.JSONLoader.prototype.supr=THREE.Loader.prototype;THREE.JSONLoader.prototype.load=function(b){var c=this,e=b.model,f=b.callback,m=b.texture_path?b.texture_path:this.extractUrlbase(e),b=new Worker(e);b.onmessage=function(b){c.createModel(b.data,f,m);c.onLoadComplete()};this.onLoadStart();b.postMessage((new Date).getTime())};
605 606 607 608 609 610 611 612 613 614 615 616 617
THREE.JSONLoader.prototype.createModel=function(b,c,e){var f=new THREE.Geometry,m=b.scale!==void 0?1/b.scale:1;this.init_materials(f,b.materials,e);(function(e){if(b.version===void 0||b.version!=2)console.error("Deprecated file format.");else{var c,m,o,u,v,t,x,w,y,A,z,D,C,F,G=b.faces;t=b.vertices;var N=b.normals,R=b.colors,H=0;for(c=0;c<b.uvs.length;c++)b.uvs[c].length&&H++;for(c=0;c<H;c++)f.faceUvs[c]=[],f.faceVertexUvs[c]=[];u=0;for(v=t.length;u<v;)x=new THREE.Vertex,x.position.x=t[u++]*e,x.position.y=
t[u++]*e,x.position.z=t[u++]*e,f.vertices.push(x);u=0;for(v=G.length;u<v;){e=G[u++];t=e&1;o=e&2;c=e&4;m=e&8;w=e&16;x=e&32;A=e&64;e&=128;t?(z=new THREE.Face4,z.a=G[u++],z.b=G[u++],z.c=G[u++],z.d=G[u++],t=4):(z=new THREE.Face3,z.a=G[u++],z.b=G[u++],z.c=G[u++],t=3);if(o)o=G[u++],z.materials=f.materials[o];o=f.faces.length;if(c)for(c=0;c<H;c++)D=b.uvs[c],y=G[u++],F=D[y*2],y=D[y*2+1],f.faceUvs[c][o]=new THREE.UV(F,y);if(m)for(c=0;c<H;c++){D=b.uvs[c];C=[];for(m=0;m<t;m++)y=G[u++],F=D[y*2],y=D[y*2+1],C[m]=
new THREE.UV(F,y);f.faceVertexUvs[c][o]=C}if(w)w=G[u++]*3,m=new THREE.Vector3,m.x=N[w++],m.y=N[w++],m.z=N[w],z.normal=m;if(x)for(c=0;c<t;c++)w=G[u++]*3,m=new THREE.Vector3,m.x=N[w++],m.y=N[w++],m.z=N[w],z.vertexNormals.push(m);if(A)x=G[u++],x=new THREE.Color(R[x]),z.color=x;if(e)for(c=0;c<t;c++)x=G[u++],x=new THREE.Color(R[x]),z.vertexColors.push(x);f.faces.push(z)}}})(m);(function(){var e,c,m,o;if(b.skinWeights){e=0;for(c=b.skinWeights.length;e<c;e+=2)m=b.skinWeights[e],o=b.skinWeights[e+1],f.skinWeights.push(new THREE.Vector4(m,
o,0,0))}if(b.skinIndices){e=0;for(c=b.skinIndices.length;e<c;e+=2)m=b.skinIndices[e],o=b.skinIndices[e+1],f.skinIndices.push(new THREE.Vector4(m,o,0,0))}f.bones=b.bones;f.animation=b.animation})();(function(e){if(b.morphTargets!==void 0){var c,m,o,u,v,t,x,w,y;c=0;for(m=b.morphTargets.length;c<m;c++){f.morphTargets[c]={};f.morphTargets[c].name=b.morphTargets[c].name;f.morphTargets[c].vertices=[];w=f.morphTargets[c].vertices;y=b.morphTargets[c].vertices;o=0;for(u=y.length;o<u;o+=3)v=y[o]*e,t=y[o+1]*
e,x=y[o+2]*e,w.push(new THREE.Vertex(new THREE.Vector3(v,t,x)))}}if(b.morphColors!==void 0){c=0;for(m=b.morphColors.length;c<m;c++){f.morphColors[c]={};f.morphColors[c].name=b.morphColors[c].name;f.morphColors[c].colors=[];u=f.morphColors[c].colors;v=b.morphColors[c].colors;e=0;for(o=v.length;e<o;e+=3)t=new THREE.Color(16755200),t.setRGB(v[e],v[e+1],v[e+2]),u.push(t)}}})(m);(function(){if(b.edges!==void 0){var e,c,m;for(e=0;e<b.edges.length;e+=2)c=b.edges[e],m=b.edges[e+1],f.edges.push(new THREE.Edge(f.vertices[c],
f.vertices[m],c,m))}})();f.computeCentroids();f.computeFaceNormals();this.hasNormals(f)&&f.computeTangents();c(f)};THREE.SceneLoader=function(){this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){};this.callbackSync=function(){};this.callbackProgress=function(){}};
THREE.SceneLoader.prototype={load:function(b,c){var e=this,f=new Worker(b);f.postMessage(0);var m=THREE.Loader.prototype.extractUrlbase(b);f.onmessage=function(b){function f(b,e){return e=="relativeToHTML"?b:m+"/"+b}function n(){for(w in O.objects)if(!S.objects[w])if(C=O.objects[w],C.geometry!==void 0){if(R=S.geometries[C.geometry]){var b=!1;X=[];for($=0;$<C.materials.length;$++)X[$]=S.materials[C.materials[$]],b=X[$]instanceof THREE.ShaderMaterial;b&&R.computeTangents();F=C.position;r=C.rotation;
q=C.quaternion;s=C.scale;q=0;X.length==0&&(X[0]=new THREE.MeshFaceMaterial);X.length>1&&(X=[new THREE.MeshFaceMaterial]);object=new THREE.Mesh(R,X);object.name=w;object.position.set(F[0],F[1],F[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=C.visible;S.scene.add(object);S.objects[w]=object;C.meshCollider&&(b=THREE.CollisionUtils.MeshColliderWBox(object),S.scene.collisions.colliders.push(b));
if(C.castsShadow)b=new THREE.ShadowVolume(R),S.scene.add(b),b.position=object.position,b.rotation=object.rotation,b.scale=object.scale;C.trigger&&C.trigger.toLowerCase()!="none"&&(b={type:C.trigger,object:C},S.triggers[object.name]=b)}}else F=C.position,r=C.rotation,q=C.quaternion,s=C.scale,q=0,object=new THREE.Object3D,object.name=w,object.position.set(F[0],F[1],F[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=C.visible!==void 0?C.visible:!1,S.scene.add(object),S.objects[w]=object,S.empties[w]=object,C.trigger&&C.trigger.toLowerCase()!="none"&&(b={type:C.trigger,object:C},S.triggers[object.name]=b)}function o(b){return function(c){S.geometries[b]=c;n();U-=1;e.onLoadComplete();v()}}function u(b){return function(e){S.geometries[b]=e}}function v(){e.callbackProgress({totalModels:p,totalTextures:ea,loadedModels:p-U,loadedTextures:ea-V},S);e.onLoadProgress();U==0&&V==0&&c(S)}var t,
x,w,y,A,z,D,C,F,G,N,R,H,J,I,X,E,O,P,U,V,p,ea,S;O=b.data;I=new THREE.BinaryLoader;P=new THREE.JSONLoader;V=U=0;S={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},triggers:{},empties:{}};b=!1;for(w in O.objects)if(C=O.objects[w],C.meshCollider){b=!0;break}if(b)S.scene.collisions=new THREE.CollisionSystem;if(O.transform){b=O.transform.position;G=O.transform.rotation;var ka=O.transform.scale;b&&S.scene.position.set(b[0],b[1],b[2]);G&&S.scene.rotation.set(G[0],
G[1],G[2]);ka&&S.scene.scale.set(ka[0],ka[1],ka[2]);(b||G||ka)&&S.scene.updateMatrix()}b=function(){V-=1;v();e.onLoadComplete()};for(A in O.cameras){G=O.cameras[A];if(G.type=="perspective")H=new THREE.Camera(G.fov,G.aspect,G.near,G.far);else if(G.type=="ortho")H=new THREE.Camera,H.projectionMatrix=THREE.Matrix4.makeOrtho(G.left,G.right,G.top,G.bottom,G.near,G.far);F=G.position;G=G.target;H.position.set(F[0],F[1],F[2]);H.target.position.set(G[0],G[1],G[2]);S.cameras[A]=H}for(y in O.lights)A=O.lights[y],
H=A.color!==void 0?A.color:16777215,G=A.intensity!==void 0?A.intensity:1,A.type=="directional"?(F=A.direction,E=new THREE.DirectionalLight(H,G),E.position.set(F[0],F[1],F[2]),E.position.normalize()):A.type=="point"?(F=A.position,d=A.distance,E=new THREE.PointLight(H,G,d),E.position.set(F[0],F[1],F[2])):A.type=="ambient"&&(E=new THREE.AmbientLight(H)),S.scene.add(E),S.lights[y]=E;for(z in O.fogs)y=O.fogs[z],y.type=="linear"?J=new THREE.Fog(0,y.near,y.far):y.type=="exp2"&&(J=new THREE.FogExp2(0,y.density)),
618 619 620 621 622 623 624 625
G=y.color,J.color.setRGB(G[0],G[1],G[2]),S.fogs[z]=J;if(S.cameras&&O.defaults.camera)S.currentCamera=S.cameras[O.defaults.camera];if(S.fogs&&O.defaults.fog)S.scene.fog=S.fogs[O.defaults.fog];G=O.defaults.bgcolor;S.bgColor=new THREE.Color;S.bgColor.setRGB(G[0],G[1],G[2]);S.bgColorAlpha=O.defaults.bgalpha;for(t in O.geometries)if(z=O.geometries[t],z.type=="bin_mesh"||z.type=="ascii_mesh")U+=1,e.onLoadStart();p=U;for(t in O.geometries)z=O.geometries[t],z.type=="cube"?(R=new THREE.CubeGeometry(z.width,
z.height,z.depth,z.segmentsWidth,z.segmentsHeight,z.segmentsDepth,null,z.flipped,z.sides),S.geometries[t]=R):z.type=="plane"?(R=new THREE.PlaneGeometry(z.width,z.height,z.segmentsWidth,z.segmentsHeight),S.geometries[t]=R):z.type=="sphere"?(R=new THREE.SphereGeometry(z.radius,z.segmentsWidth,z.segmentsHeight),S.geometries[t]=R):z.type=="cylinder"?(R=new THREE.CylinderGeometry(z.topRad,z.botRad,z.height,z.radSegs,z.heightSegs),S.geometries[t]=R):z.type=="torus"?(R=new THREE.TorusGeometry(z.radius,z.tube,
z.segmentsR,z.segmentsT),S.geometries[t]=R):z.type=="icosahedron"?(R=new THREE.IcosahedronGeometry(z.subdivisions),S.geometries[t]=R):z.type=="bin_mesh"?I.load({model:f(z.url,O.urlBaseType),callback:o(t)}):z.type=="ascii_mesh"?P.load({model:f(z.url,O.urlBaseType),callback:o(t)}):z.type=="embedded_mesh"&&(z=O.embeds[z.id])&&P.createModel(z,u(t),"");for(D in O.textures)if(t=O.textures[D],t.url instanceof Array){V+=t.url.length;for(I=0;I<t.url.length;I++)e.onLoadStart()}else V+=1,e.onLoadStart();ea=
V;for(D in O.textures){t=O.textures[D];if(t.mapping!=void 0&&THREE[t.mapping]!=void 0)t.mapping=new THREE[t.mapping];if(t.url instanceof Array){I=[];for(var $=0;$<t.url.length;$++)I[$]=f(t.url[$],O.urlBaseType);I=THREE.ImageUtils.loadTextureCube(I,t.mapping,b)}else{I=THREE.ImageUtils.loadTexture(f(t.url,O.urlBaseType),t.mapping,b);if(THREE[t.minFilter]!=void 0)I.minFilter=THREE[t.minFilter];if(THREE[t.magFilter]!=void 0)I.magFilter=THREE[t.magFilter];if(t.repeat){I.repeat.set(t.repeat[0],t.repeat[1]);
if(t.repeat[0]!=1)I.wrapS=THREE.RepeatWrapping;if(t.repeat[1]!=1)I.wrapT=THREE.RepeatWrapping}t.offset&&I.offset.set(t.offset[0],t.offset[1]);if(t.wrap){P={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(P[t.wrap[0]]!==void 0)I.wrapS=P[t.wrap[0]];if(P[t.wrap[1]]!==void 0)I.wrapT=P[t.wrap[1]]}}S.textures[D]=I}for(x in O.materials){D=O.materials[x];for(N in D.parameters)if(N=="envMap"||N=="map"||N=="lightMap")D.parameters[N]=S.textures[D.parameters[N]];else if(N=="shading")D.parameters[N]=
D.parameters[N]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(N=="blending")D.parameters[N]=THREE[D.parameters[N]]?THREE[D.parameters[N]]:THREE.NormalBlending;else if(N=="combine")D.parameters[N]=D.parameters[N]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(N=="vertexColors")if(D.parameters[N]=="face")D.parameters[N]=THREE.FaceColors;else if(D.parameters[N])D.parameters[N]=THREE.VertexColors;if(D.parameters.opacity!==void 0&&D.parameters.opacity<1)D.parameters.transparent=
!0;if(D.parameters.normalMap){t=THREE.ShaderUtils.lib.normal;b=THREE.UniformsUtils.clone(t.uniforms);I=D.parameters.color;P=D.parameters.specular;z=D.parameters.ambient;J=D.parameters.shininess;b.tNormal.texture=S.textures[D.parameters.normalMap];if(D.parameters.normalMapFactor)b.uNormalScale.value=D.parameters.normalMapFactor;if(D.parameters.map)b.tDiffuse.texture=D.parameters.map,b.enableDiffuse.value=!0;if(D.parameters.lightMap)b.tAO.texture=D.parameters.lightMap,b.enableAO.value=!0;if(D.parameters.specularMap)b.tSpecular.texture=
S.textures[D.parameters.specularMap],b.enableSpecular.value=!0;b.uDiffuseColor.value.setHex(I);b.uSpecularColor.value.setHex(P);b.uAmbientColor.value.setHex(z);b.uShininess.value=J;if(D.parameters.opacity)b.uOpacity.value=D.parameters.opacity;D=new THREE.ShaderMaterial({fragmentShader:t.fragmentShader,vertexShader:t.vertexShader,uniforms:b,lights:!0,fog:!0})}else D=new THREE[D.type](D.parameters);S.materials[x]=D}n();e.callbackSync(S)}},constructor:THREE.SceneLoader};THREE.UTF8Loader=function(){};
A
alteredq 已提交
626
THREE.UTF8Loader.prototype=new THREE.UTF8Loader;THREE.UTF8Loader.prototype.constructor=THREE.UTF8Loader;
627 628
THREE.UTF8Loader.prototype.load=function(b){var c=new XMLHttpRequest,e=b.model,f=b.callback,m=b.scale!==void 0?b.scale:1,k=b.offsetX!==void 0?b.offsetX:0,h=b.offsetY!==void 0?b.offsetY:0,n=b.offsetZ!==void 0?b.offsetZ:0;c.onreadystatechange=function(){c.readyState==4?c.status==200||c.status==0?THREE.UTF8Loader.prototype.createModel(c.responseText,f,m,k,h,n):alert("Couldn't load ["+e+"] ["+c.status+"]"):c.readyState!=3&&c.readyState==2&&c.getResponseHeader("Content-Length")};c.open("GET",e,!0);c.send(null)};
THREE.UTF8Loader.prototype.decompressMesh=function(b){var c=b.charCodeAt(0);c>=57344&&(c-=2048);c++;for(var e=new Float32Array(8*c),f=1,m=0;m<8;m++){for(var k=0,h=0;h<c;++h){var n=b.charCodeAt(h+f);k+=n>>1^-(n&1);e[8*h+m]=k}f+=c}c=b.length-f;k=new Uint16Array(c);for(m=h=0;m<c;m++)n=b.charCodeAt(m+f),k[m]=h-n,n==0&&h++;return[e,k]};
629 630 631
THREE.UTF8Loader.prototype.createModel=function(b,c,e,f,m,k){var h=function(){var c=this;c.materials=[];THREE.Geometry.call(this);var h=THREE.UTF8Loader.prototype.decompressMesh(b),u=[],v=[];(function(b,h,o){for(var u,v,z,D=b.length;o<D;o+=h)u=b[o],v=b[o+1],z=b[o+2],u=u/16383*e,v=v/16383*e,z=z/16383*e,u+=f,v+=m,z+=k,c.vertices.push(new THREE.Vertex(new THREE.Vector3(u,v,z)))})(h[0],8,0);(function(b,e,c){for(var f,h,k=b.length;c<k;c+=e)f=b[c],h=b[c+1],f/=1023,h/=1023,v.push(f,1-h)})(h[0],8,3);(function(b,
e,c){for(var f,h,k,m=b.length;c<m;c+=e)f=b[c],h=b[c+1],k=b[c+2],f=(f-512)/511,h=(h-512)/511,k=(k-512)/511,u.push(f,h,k)})(h[0],8,5);(function(b){var e,f,h,k,m,o,C,F,G,N=b.length;for(e=0;e<N;e+=3){f=b[e];h=b[e+1];k=b[e+2];m=c;F=f;G=h;o=k;C=f;var R=h,H=k,J=m.materials[0],I=u[R*3],X=u[R*3+1],R=u[R*3+2],E=u[H*3],O=u[H*3+1],H=u[H*3+2];C=new THREE.Vector3(u[C*3],u[C*3+1],u[C*3+2]);R=new THREE.Vector3(I,X,R);H=new THREE.Vector3(E,O,H);m.faces.push(new THREE.Face3(F,G,o,[C,R,H],null,J));m=v[f*2];f=v[f*2+
1];o=v[h*2];C=v[h*2+1];F=v[k*2];G=v[k*2+1];k=c.faceVertexUvs[0];h=o;o=C;C=[];C.push(new THREE.UV(m,f));C.push(new THREE.UV(h,o));C.push(new THREE.UV(F,G));k.push(C)}})(h[1]);this.computeCentroids();this.computeFaceNormals()};h.prototype=new THREE.Geometry;h.prototype.constructor=h;c(new h)};
632
THREE.MarchingCubes=function(b,c){THREE.Object3D.call(this);this.materials=c instanceof Array?c:[c];this.init=function(b){this.isolation=80;this.size=b;this.size2=this.size*this.size;this.size3=this.size2*this.size;this.halfsize=this.size/2;this.delta=2/this.size;this.yd=this.size;this.zd=this.size2;this.field=new Float32Array(this.size3);this.normal_cache=new Float32Array(this.size3*3);this.vlist=new Float32Array(36);this.nlist=new Float32Array(36);this.firstDraw=!0;this.maxCount=4096;this.count=
633 634
0;this.hasNormal=this.hasPos=!1;this.positionArray=new Float32Array(this.maxCount*3);this.normalArray=new Float32Array(this.maxCount*3)};this.lerp=function(b,c,m){return b+(c-b)*m};this.VIntX=function(b,c,m,k,h,n,o,u,v,t){h=(h-v)/(t-v);v=this.normal_cache;c[k]=n+h*this.delta;c[k+1]=o;c[k+2]=u;m[k]=this.lerp(v[b],v[b+3],h);m[k+1]=this.lerp(v[b+1],v[b+4],h);m[k+2]=this.lerp(v[b+2],v[b+5],h)};this.VIntY=function(b,c,m,k,h,n,o,u,v,t){h=(h-v)/(t-v);v=this.normal_cache;c[k]=n;c[k+1]=o+h*this.delta;c[k+
2]=u;c=b+this.yd*3;m[k]=this.lerp(v[b],v[c],h);m[k+1]=this.lerp(v[b+1],v[c+1],h);m[k+2]=this.lerp(v[b+2],v[c+2],h)};this.VIntZ=function(b,c,m,k,h,n,o,u,v,t){h=(h-v)/(t-v);v=this.normal_cache;c[k]=n;c[k+1]=o;c[k+2]=u+h*this.delta;c=b+this.zd*3;m[k]=this.lerp(v[b],v[c],h);m[k+1]=this.lerp(v[b+1],v[c+1],h);m[k+2]=this.lerp(v[b+2],v[c+2],h)};this.compNorm=function(b){var c=b*3;this.normal_cache[c]==0&&(this.normal_cache[c]=this.field[b-1]-this.field[b+1],this.normal_cache[c+1]=this.field[b-this.yd]-this.field[b+
635 636
this.yd],this.normal_cache[c+2]=this.field[b-this.zd]-this.field[b+this.zd])};this.polygonize=function(b,c,m,k,h,n){var o=k+1,u=k+this.yd,v=k+this.zd,t=o+this.yd,x=o+this.zd,w=k+this.yd+this.zd,y=o+this.yd+this.zd,A=0,z=this.field[k],D=this.field[o],C=this.field[u],F=this.field[t],G=this.field[v],N=this.field[x],R=this.field[w],H=this.field[y];z<h&&(A|=1);D<h&&(A|=2);C<h&&(A|=8);F<h&&(A|=4);G<h&&(A|=16);N<h&&(A|=32);R<h&&(A|=128);H<h&&(A|=64);var J=THREE.edgeTable[A];if(J==0)return 0;var I=this.delta,
X=b+I,E=c+I,I=m+I;J&1&&(this.compNorm(k),this.compNorm(o),this.VIntX(k*3,this.vlist,this.nlist,0,h,b,c,m,z,D));J&2&&(this.compNorm(o),this.compNorm(t),this.VIntY(o*3,this.vlist,this.nlist,3,h,X,c,m,D,F));J&4&&(this.compNorm(u),this.compNorm(t),this.VIntX(u*3,this.vlist,this.nlist,6,h,b,E,m,C,F));J&8&&(this.compNorm(k),this.compNorm(u),this.VIntY(k*3,this.vlist,this.nlist,9,h,b,c,m,z,C));J&16&&(this.compNorm(v),this.compNorm(x),this.VIntX(v*3,this.vlist,this.nlist,12,h,b,c,I,G,N));J&32&&(this.compNorm(x),
637
this.compNorm(y),this.VIntY(x*3,this.vlist,this.nlist,15,h,X,c,I,N,H));J&64&&(this.compNorm(w),this.compNorm(y),this.VIntX(w*3,this.vlist,this.nlist,18,h,b,E,I,R,H));J&128&&(this.compNorm(v),this.compNorm(w),this.VIntY(v*3,this.vlist,this.nlist,21,h,b,c,I,G,R));J&256&&(this.compNorm(k),this.compNorm(v),this.VIntZ(k*3,this.vlist,this.nlist,24,h,b,c,m,z,G));J&512&&(this.compNorm(o),this.compNorm(x),this.VIntZ(o*3,this.vlist,this.nlist,27,h,X,c,m,D,N));J&1024&&(this.compNorm(t),this.compNorm(y),this.VIntZ(t*
638
3,this.vlist,this.nlist,30,h,X,E,m,F,H));J&2048&&(this.compNorm(u),this.compNorm(w),this.VIntZ(u*3,this.vlist,this.nlist,33,h,b,E,m,C,R));A<<=4;for(h=k=0;THREE.triTable[A+h]!=-1;)b=A+h,c=b+1,m=b+2,this.posnormtriv(this.vlist,this.nlist,3*THREE.triTable[b],3*THREE.triTable[c],3*THREE.triTable[m],n),h+=3,k++;return k};this.posnormtriv=function(b,c,m,k,h,n){var o=this.count*3;this.positionArray[o]=b[m];this.positionArray[o+1]=b[m+1];this.positionArray[o+2]=b[m+2];this.positionArray[o+3]=b[k];this.positionArray[o+
639 640
4]=b[k+1];this.positionArray[o+5]=b[k+2];this.positionArray[o+6]=b[h];this.positionArray[o+7]=b[h+1];this.positionArray[o+8]=b[h+2];this.normalArray[o]=c[m];this.normalArray[o+1]=c[m+1];this.normalArray[o+2]=c[m+2];this.normalArray[o+3]=c[k];this.normalArray[o+4]=c[k+1];this.normalArray[o+5]=c[k+2];this.normalArray[o+6]=c[h];this.normalArray[o+7]=c[h+1];this.normalArray[o+8]=c[h+2];this.hasNormal=this.hasPos=!0;this.count+=3;this.count>=this.maxCount-3&&n(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;c<this.positionArray.length;c++)this.positionArray[c]=0;b(this)}};this.addBall=function(b,c,m,k,h){var n=this.size*Math.sqrt(k/h),o=m*this.size,u=c*this.size,v=b*this.size,t=Math.floor(o-n);t<1&&(t=1);o=Math.floor(o+n);o>this.size-1&&(o=this.size-1);var x=Math.floor(u-n);x<1&&(x=1);u=Math.floor(u+n);u>this.size-1&&(u=this.size-1);var w=Math.floor(v-n);w<1&&(w=1);n=Math.floor(v+n);n>this.size-1&&(n=this.size-
641
1);for(var y,A,z,D,C,F;t<o;t++){v=this.size2*t;A=t/this.size-m;C=A*A;for(A=x;A<u;A++){z=v+this.size*A;y=A/this.size-c;F=y*y;for(y=w;y<n;y++)D=y/this.size-b,D=k/(1.0E-6+D*D+F+C)-h,D>0&&(this.field[z+y]+=D)}}};this.addPlaneX=function(b,c){var m,k,h,n,o,u=this.size,v=this.yd,t=this.zd,x=this.field,w=u*Math.sqrt(b/c);w>u&&(w=u);for(m=0;m<w;m++)if(k=m/u,k*=k,n=b/(1.0E-4+k)-c,n>0)for(k=0;k<u;k++){o=m+k*v;for(h=0;h<u;h++)x[t*h+o]+=n}};this.addPlaneY=function(b,c){var m,k,h,n,o,u,v=this.size,t=this.yd,x=
642 643 644
this.zd,w=this.field,y=v*Math.sqrt(b/c);y>v&&(y=v);for(k=0;k<y;k++)if(m=k/v,m*=m,n=b/(1.0E-4+m)-c,n>0){o=k*t;for(m=0;m<v;m++){u=o+m;for(h=0;h<v;h++)w[x*h+u]+=n}}};this.addPlaneZ=function(b,c){var m,k,h,n,o,u;size=this.size;yd=this.yd;zd=this.zd;field=this.field;dist=size*Math.sqrt(b/c);dist>size&&(dist=size);for(h=0;h<dist;h++)if(m=h/size,m*=m,n=b/(1.0E-4+m)-c,n>0){o=zd*h;for(k=0;k<size;k++){u=o+k*yd;for(m=0;m<size;m++)field[u+m]+=n}}};this.reset=function(){var b;for(b=0;b<this.size3;b++)this.normal_cache[b*
3]=0,this.field[b]=0};this.render=function(b){this.begin();var c,m,k,h,n,o,u,v,t,x=this.size-2;for(h=1;h<x;h++){t=this.size2*h;u=(h-this.halfsize)/this.halfsize;for(k=1;k<x;k++){v=t+this.size*k;o=(k-this.halfsize)/this.halfsize;for(m=1;m<x;m++)n=(m-this.halfsize)/this.halfsize,c=v+m,this.polygonize(n,o,u,c,this.isolation,b)}}this.end(b)};this.generateGeometry=function(){var b=0,c=new THREE.Geometry,m=[];this.render(function(k){var h,n,o,u,v,t,x,w;for(h=0;h<k.count;h++)x=h*3,v=x+1,w=x+2,n=k.positionArray[x],
o=k.positionArray[v],u=k.positionArray[w],t=new THREE.Vector3(n,o,u),n=k.normalArray[x],o=k.normalArray[v],u=k.normalArray[w],x=new THREE.Vector3(n,o,u),x.normalize(),v=new THREE.Vertex(t),c.vertices.push(v),m.push(x);nfaces=k.count/3;for(h=0;h<nfaces;h++)x=(b+h)*3,v=x+1,w=x+2,t=m[x],n=m[v],o=m[w],x=new THREE.Face3(x,v,w,[t,n,o]),c.faces.push(x);b+=nfaces;k.count=0});return c};this.init(b)};THREE.MarchingCubes.prototype=new THREE.Object3D;THREE.MarchingCubes.prototype.constructor=THREE.MarchingCubes;
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
THREE.edgeTable=new Int32Array([0,265,515,778,1030,1295,1541,1804,2060,2309,2575,2822,3082,3331,3593,3840,400,153,915,666,1430,1183,1941,1692,2460,2197,2975,2710,3482,3219,3993,3728,560,825,51,314,1590,1855,1077,1340,2620,2869,2111,2358,3642,3891,3129,3376,928,681,419,170,1958,1711,1445,1196,2988,2725,2479,2214,4010,3747,3497,3232,1120,1385,1635,1898,102,367,613,876,3180,3429,3695,3942,2154,2403,2665,2912,1520,1273,2035,1786,502,255,1013,764,3580,3317,4095,3830,2554,2291,3065,2800,1616,1881,1107,
1370,598,863,85,348,3676,3925,3167,3414,2650,2899,2137,2384,1984,1737,1475,1226,966,719,453,204,4044,3781,3535,3270,3018,2755,2505,2240,2240,2505,2755,3018,3270,3535,3781,4044,204,453,719,966,1226,1475,1737,1984,2384,2137,2899,2650,3414,3167,3925,3676,348,85,863,598,1370,1107,1881,1616,2800,3065,2291,2554,3830,4095,3317,3580,764,1013,255,502,1786,2035,1273,1520,2912,2665,2403,2154,3942,3695,3429,3180,876,613,367,102,1898,1635,1385,1120,3232,3497,3747,4010,2214,2479,2725,2988,1196,1445,1711,1958,170,
419,681,928,3376,3129,3891,3642,2358,2111,2869,2620,1340,1077,1855,1590,314,51,825,560,3728,3993,3219,3482,2710,2975,2197,2460,1692,1941,1183,1430,666,915,153,400,3840,3593,3331,3082,2822,2575,2309,2060,1804,1541,1295,1030,778,515,265,0]);
THREE.triTable=new Int32Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,9,8,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,2,10,0,2,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,8,3,2,10,8,10,9,8,-1,-1,-1,-1,-1,-1,-1,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,8,11,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,11,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,1,11,2,1,9,11,9,8,11,-1,-1,-1,-1,-1,-1,-1,3,10,1,11,10,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,10,1,0,8,10,8,11,10,-1,-1,-1,-1,-1,-1,-1,3,9,0,3,11,9,11,10,9,-1,-1,-1,-1,-1,-1,-1,9,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,7,3,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,1,9,4,7,1,7,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,4,7,3,0,4,1,2,10,-1,-1,-1,-1,-1,-1,-1,9,2,10,9,0,2,8,4,7,
-1,-1,-1,-1,-1,-1,-1,2,10,9,2,9,7,2,7,3,7,9,4,-1,-1,-1,-1,8,4,7,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,4,7,11,2,4,2,0,4,-1,-1,-1,-1,-1,-1,-1,9,0,1,8,4,7,2,3,11,-1,-1,-1,-1,-1,-1,-1,4,7,11,9,4,11,9,11,2,9,2,1,-1,-1,-1,-1,3,10,1,3,11,10,7,8,4,-1,-1,-1,-1,-1,-1,-1,1,11,10,1,4,11,1,0,4,7,11,4,-1,-1,-1,-1,4,7,8,9,0,11,9,11,10,11,0,3,-1,-1,-1,-1,4,7,11,4,11,9,9,11,10,-1,-1,-1,-1,-1,-1,-1,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,5,4,1,5,0,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,8,5,4,8,3,5,3,1,5,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,10,4,9,5,-1,-1,-1,-1,-1,-1,-1,5,2,10,5,4,2,4,0,2,-1,-1,-1,-1,-1,-1,-1,2,10,5,3,2,5,3,5,4,3,4,8,-1,-1,-1,-1,9,5,4,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,0,8,11,4,9,5,-1,-1,-1,-1,-1,-1,-1,0,5,4,0,1,5,2,3,11,-1,-1,-1,-1,-1,-1,-1,2,1,5,2,5,8,2,8,11,4,8,5,-1,-1,-1,-1,10,3,11,10,1,3,9,5,4,-1,-1,-1,-1,-1,-1,-1,4,9,5,0,8,1,8,10,1,8,11,10,-1,-1,-1,-1,5,4,0,5,0,11,5,11,10,11,0,3,-1,-1,-1,-1,5,4,8,5,
8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,9,7,8,5,7,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,3,0,9,5,3,5,7,3,-1,-1,-1,-1,-1,-1,-1,0,7,8,0,1,7,1,5,7,-1,-1,-1,-1,-1,-1,-1,1,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,7,8,9,5,7,10,1,2,-1,-1,-1,-1,-1,-1,-1,10,1,2,9,5,0,5,3,0,5,7,3,-1,-1,-1,-1,8,0,2,8,2,5,8,5,7,10,5,2,-1,-1,-1,-1,2,10,5,2,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,7,9,5,7,8,9,3,11,2,-1,-1,-1,-1,-1,-1,-1,9,5,7,9,7,2,9,2,0,2,7,11,-1,-1,-1,-1,2,3,11,0,1,8,1,7,8,1,5,7,-1,-1,-1,-1,11,2,1,11,1,7,7,1,5,-1,-1,-1,-1,-1,-1,
-1,9,5,8,8,5,7,10,1,3,10,3,11,-1,-1,-1,-1,5,7,0,5,0,9,7,11,0,1,0,10,11,10,0,-1,11,10,0,11,0,3,10,5,0,8,0,7,5,7,0,-1,11,10,5,7,11,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,0,1,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,1,9,8,5,10,6,-1,-1,-1,-1,-1,-1,-1,1,6,5,2,6,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,6,5,1,2,6,3,0,8,-1,-1,-1,-1,-1,-1,-1,9,6,5,9,0,6,0,2,6,-1,-1,-1,-1,-1,-1,-1,5,9,8,5,8,2,5,2,6,3,2,8,-1,-1,-1,-1,2,3,11,10,6,
5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,0,8,11,2,0,10,6,5,-1,-1,-1,-1,-1,-1,-1,0,1,9,2,3,11,5,10,6,-1,-1,-1,-1,-1,-1,-1,5,10,6,1,9,2,9,11,2,9,8,11,-1,-1,-1,-1,6,3,11,6,5,3,5,1,3,-1,-1,-1,-1,-1,-1,-1,0,8,11,0,11,5,0,5,1,5,11,6,-1,-1,-1,-1,3,11,6,0,3,6,0,6,5,0,5,9,-1,-1,-1,-1,6,5,9,6,9,11,11,9,8,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,4,7,3,6,5,10,-1,-1,-1,-1,-1,-1,-1,1,9,0,5,10,6,8,4,7,-1,-1,-1,-1,-1,-1,-1,10,6,5,1,9,7,1,7,3,7,9,4,-1,-1,-1,-1,6,1,2,6,5,1,4,7,8,-1,-1,-1,-1,
-1,-1,-1,1,2,5,5,2,6,3,0,4,3,4,7,-1,-1,-1,-1,8,4,7,9,0,5,0,6,5,0,2,6,-1,-1,-1,-1,7,3,9,7,9,4,3,2,9,5,9,6,2,6,9,-1,3,11,2,7,8,4,10,6,5,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,2,4,2,0,2,7,11,-1,-1,-1,-1,0,1,9,4,7,8,2,3,11,5,10,6,-1,-1,-1,-1,9,2,1,9,11,2,9,4,11,7,11,4,5,10,6,-1,8,4,7,3,11,5,3,5,1,5,11,6,-1,-1,-1,-1,5,1,11,5,11,6,1,0,11,7,11,4,0,4,11,-1,0,5,9,0,6,5,0,3,6,11,6,3,8,4,7,-1,6,5,9,6,9,11,4,7,9,7,11,9,-1,-1,-1,-1,10,4,9,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,10,6,4,9,10,0,8,3,-1,-1,-1,-1,-1,-1,-1,
10,0,1,10,6,0,6,4,0,-1,-1,-1,-1,-1,-1,-1,8,3,1,8,1,6,8,6,4,6,1,10,-1,-1,-1,-1,1,4,9,1,2,4,2,6,4,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,9,2,4,9,2,6,4,-1,-1,-1,-1,0,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,3,2,8,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,10,4,9,10,6,4,11,2,3,-1,-1,-1,-1,-1,-1,-1,0,8,2,2,8,11,4,9,10,4,10,6,-1,-1,-1,-1,3,11,2,0,1,6,0,6,4,6,1,10,-1,-1,-1,-1,6,4,1,6,1,10,4,8,1,2,1,11,8,11,1,-1,9,6,4,9,3,6,9,1,3,11,6,3,-1,-1,-1,-1,8,11,1,8,1,0,11,6,1,9,1,4,6,4,1,-1,3,11,6,3,6,0,0,6,4,-1,-1,-1,-1,-1,-1,-1,
6,4,8,11,6,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,10,6,7,8,10,8,9,10,-1,-1,-1,-1,-1,-1,-1,0,7,3,0,10,7,0,9,10,6,7,10,-1,-1,-1,-1,10,6,7,1,10,7,1,7,8,1,8,0,-1,-1,-1,-1,10,6,7,10,7,1,1,7,3,-1,-1,-1,-1,-1,-1,-1,1,2,6,1,6,8,1,8,9,8,6,7,-1,-1,-1,-1,2,6,9,2,9,1,6,7,9,0,9,3,7,3,9,-1,7,8,0,7,0,6,6,0,2,-1,-1,-1,-1,-1,-1,-1,7,3,2,6,7,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,11,10,6,8,10,8,9,8,6,7,-1,-1,-1,-1,2,0,7,2,7,11,0,9,7,6,7,10,9,10,7,-1,1,8,0,1,7,8,1,10,7,6,7,10,2,3,11,-1,11,2,1,11,1,7,10,6,1,6,7,1,-1,-1,-1,-1,
8,9,6,8,6,7,9,1,6,11,6,3,1,3,6,-1,0,9,1,11,6,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,8,0,7,0,6,3,11,0,11,6,0,-1,-1,-1,-1,7,11,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,1,9,8,3,1,11,7,6,-1,-1,-1,-1,-1,-1,-1,10,1,2,6,11,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,8,6,11,7,-1,-1,-1,-1,-1,-1,-1,2,9,0,2,10,9,6,11,7,-1,-1,-1,-1,-1,-1,-1,6,11,7,2,10,3,10,8,3,10,9,8,-1,-1,-1,-1,7,
2,3,6,2,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,0,8,7,6,0,6,2,0,-1,-1,-1,-1,-1,-1,-1,2,7,6,2,3,7,0,1,9,-1,-1,-1,-1,-1,-1,-1,1,6,2,1,8,6,1,9,8,8,7,6,-1,-1,-1,-1,10,7,6,10,1,7,1,3,7,-1,-1,-1,-1,-1,-1,-1,10,7,6,1,7,10,1,8,7,1,0,8,-1,-1,-1,-1,0,3,7,0,7,10,0,10,9,6,10,7,-1,-1,-1,-1,7,6,10,7,10,8,8,10,9,-1,-1,-1,-1,-1,-1,-1,6,8,4,11,8,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,6,11,3,0,6,0,4,6,-1,-1,-1,-1,-1,-1,-1,8,6,11,8,4,6,9,0,1,-1,-1,-1,-1,-1,-1,-1,9,4,6,9,6,3,9,3,1,11,3,6,-1,-1,-1,-1,6,8,4,6,11,8,2,10,1,-1,-1,-1,
-1,-1,-1,-1,1,2,10,3,0,11,0,6,11,0,4,6,-1,-1,-1,-1,4,11,8,4,6,11,0,2,9,2,10,9,-1,-1,-1,-1,10,9,3,10,3,2,9,4,3,11,3,6,4,6,3,-1,8,2,3,8,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,0,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,4,2,4,6,4,3,8,-1,-1,-1,-1,1,9,4,1,4,2,2,4,6,-1,-1,-1,-1,-1,-1,-1,8,1,3,8,6,1,8,4,6,6,10,1,-1,-1,-1,-1,10,1,0,10,0,6,6,0,4,-1,-1,-1,-1,-1,-1,-1,4,6,3,4,3,8,6,10,3,0,3,9,10,9,3,-1,10,9,4,6,10,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,5,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,5,11,7,6,
-1,-1,-1,-1,-1,-1,-1,5,0,1,5,4,0,7,6,11,-1,-1,-1,-1,-1,-1,-1,11,7,6,8,3,4,3,5,4,3,1,5,-1,-1,-1,-1,9,5,4,10,1,2,7,6,11,-1,-1,-1,-1,-1,-1,-1,6,11,7,1,2,10,0,8,3,4,9,5,-1,-1,-1,-1,7,6,11,5,4,10,4,2,10,4,0,2,-1,-1,-1,-1,3,4,8,3,5,4,3,2,5,10,5,2,11,7,6,-1,7,2,3,7,6,2,5,4,9,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,6,0,6,2,6,8,7,-1,-1,-1,-1,3,6,2,3,7,6,1,5,0,5,4,0,-1,-1,-1,-1,6,2,8,6,8,7,2,1,8,4,8,5,1,5,8,-1,9,5,4,10,1,6,1,7,6,1,3,7,-1,-1,-1,-1,1,6,10,1,7,6,1,0,7,8,7,0,9,5,4,-1,4,0,10,4,10,5,0,3,10,6,10,7,3,7,10,
-1,7,6,10,7,10,8,5,4,10,4,8,10,-1,-1,-1,-1,6,9,5,6,11,9,11,8,9,-1,-1,-1,-1,-1,-1,-1,3,6,11,0,6,3,0,5,6,0,9,5,-1,-1,-1,-1,0,11,8,0,5,11,0,1,5,5,6,11,-1,-1,-1,-1,6,11,3,6,3,5,5,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,11,9,11,8,11,5,6,-1,-1,-1,-1,0,11,3,0,6,11,0,9,6,5,6,9,1,2,10,-1,11,8,5,11,5,6,8,0,5,10,5,2,0,2,5,-1,6,11,3,6,3,5,2,10,3,10,5,3,-1,-1,-1,-1,5,8,9,5,2,8,5,6,2,3,8,2,-1,-1,-1,-1,9,5,6,9,6,0,0,6,2,-1,-1,-1,-1,-1,-1,-1,1,5,8,1,8,0,5,6,8,3,8,2,6,2,8,-1,1,5,6,2,1,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
1,3,6,1,6,10,3,8,6,5,6,9,8,9,6,-1,10,1,0,10,0,6,9,5,0,5,6,0,-1,-1,-1,-1,0,3,8,5,6,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,7,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,11,7,5,8,3,0,-1,-1,-1,-1,-1,-1,-1,5,11,7,5,10,11,1,9,0,-1,-1,-1,-1,-1,-1,-1,10,7,5,10,11,7,9,8,1,8,3,1,-1,-1,-1,-1,11,1,2,11,7,1,7,5,1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,7,1,7,5,7,2,11,-1,-1,-1,-1,9,7,5,9,2,7,9,0,2,2,11,7,-1,-1,-1,-1,7,5,2,7,2,11,5,9,2,3,2,8,9,8,2,-1,2,5,10,2,3,5,3,7,5,-1,-1,
-1,-1,-1,-1,-1,8,2,0,8,5,2,8,7,5,10,2,5,-1,-1,-1,-1,9,0,1,5,10,3,5,3,7,3,10,2,-1,-1,-1,-1,9,8,2,9,2,1,8,7,2,10,2,5,7,5,2,-1,1,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,7,0,7,1,1,7,5,-1,-1,-1,-1,-1,-1,-1,9,0,3,9,3,5,5,3,7,-1,-1,-1,-1,-1,-1,-1,9,8,7,5,9,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,5,8,4,5,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,5,0,4,5,11,0,5,10,11,11,3,0,-1,-1,-1,-1,0,1,9,8,4,10,8,10,11,10,4,5,-1,-1,-1,-1,10,11,4,10,4,5,11,3,4,9,4,1,3,1,4,-1,2,5,1,2,8,5,2,11,8,4,5,8,-1,-1,-1,-1,0,4,11,0,11,3,4,5,11,
2,11,1,5,1,11,-1,0,2,5,0,5,9,2,11,5,4,5,8,11,8,5,-1,9,4,5,2,11,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,5,10,3,5,2,3,4,5,3,8,4,-1,-1,-1,-1,5,10,2,5,2,4,4,2,0,-1,-1,-1,-1,-1,-1,-1,3,10,2,3,5,10,3,8,5,4,5,8,0,1,9,-1,5,10,2,5,2,4,1,9,2,9,4,2,-1,-1,-1,-1,8,4,5,8,5,3,3,5,1,-1,-1,-1,-1,-1,-1,-1,0,4,5,1,0,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,4,5,8,5,3,9,0,5,0,3,5,-1,-1,-1,-1,9,4,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,11,7,4,9,11,9,10,11,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,7,9,11,7,9,10,11,-1,-1,-1,-1,1,10,11,1,11,
4,1,4,0,7,4,11,-1,-1,-1,-1,3,1,4,3,4,8,1,10,4,7,4,11,10,11,4,-1,4,11,7,9,11,4,9,2,11,9,1,2,-1,-1,-1,-1,9,7,4,9,11,7,9,1,11,2,11,1,0,8,3,-1,11,7,4,11,4,2,2,4,0,-1,-1,-1,-1,-1,-1,-1,11,7,4,11,4,2,8,3,4,3,2,4,-1,-1,-1,-1,2,9,10,2,7,9,2,3,7,7,4,9,-1,-1,-1,-1,9,10,7,9,7,4,10,2,7,8,7,0,2,0,7,-1,3,7,10,3,10,2,7,4,10,1,10,0,4,0,10,-1,1,10,2,8,7,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,7,1,3,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,0,8,1,8,7,1,-1,-1,-1,-1,4,0,3,7,4,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,8,7,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,11,9,10,-1,-1,-1,-1,-1,-1,-1,0,1,10,0,10,8,8,10,11,-1,-1,-1,-1,-1,-1,-1,3,1,10,11,3,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,11,1,11,9,9,11,8,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,1,2,9,2,11,9,-1,-1,-1,-1,0,2,11,8,0,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,2,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,10,8,9,-1,-1,-1,-1,-1,-1,-1,9,10,2,0,9,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,0,1,8,1,10,8,-1,-1,-1,-1,1,10,
2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,8,9,1,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,9,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,3,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]);
M
Mr.doob 已提交
669
THREE.Trident=function(){THREE.Object3D.call(this);var b=new THREE.Geometry;b.vertices.push(new THREE.Vertex);b.vertices.push(new THREE.Vertex(new THREE.Vector3(0,100,0)));var c=new THREE.CylinderGeometry(0,5,25,5,1),e=new THREE.Line(b,new THREE.LineBasicMaterial({color:16711680}));e.rotation.z=-Math.PI/2;this.add(e);e=new THREE.Mesh(c,new THREE.MeshBasicMaterial({color:16711680}));e.position.x=100;e.rotation.z=-Math.PI/2;this.add(e);e=new THREE.Line(b,new THREE.LineBasicMaterial({color:65280}));
M
Mr.doob 已提交
670 671
this.add(e);e=new THREE.Mesh(c,new THREE.MeshBasicMaterial({color:65280}));e.position.y=100;this.add(e);e=new THREE.Line(b,new THREE.LineBasicMaterial({color:255}));e.rotation.x=Math.PI/2;this.add(e);e=new THREE.Mesh(c,new THREE.MeshBasicMaterial({color:255}));e.position.z=100;e.rotation.x=Math.PI/2;this.add(e)};THREE.Trident.prototype=new THREE.Object3D;THREE.Trident.prototype.constructor=THREE.Trident;THREE.PlaneCollider=function(b,c){this.point=b;this.normal=c};
THREE.SphereCollider=function(b,c){this.center=b;this.radius=c;this.radiusSq=c*c};THREE.BoxCollider=function(b,c){this.min=b;this.max=c;this.dynamic=!0;this.normal=new THREE.Vector3};THREE.MeshCollider=function(b,c){this.mesh=b;this.box=c;this.numFaces=this.mesh.geometry.faces.length;this.normal=new THREE.Vector3};THREE.CollisionSystem=function(){this.collisionNormal=new THREE.Vector3;this.colliders=[];this.hits=[]};THREE.Collisions=new THREE.CollisionSystem;
672
THREE.CollisionSystem.prototype.merge=function(b){Array.prototype.push.apply(this.colliders,b.colliders);Array.prototype.push.apply(this.hits,b.hits)};THREE.CollisionSystem.prototype.rayCastAll=function(b){b.direction.normalize();this.hits.length=0;var c,e,f,m,k=0;c=0;for(e=this.colliders.length;c<e;c++)if(m=this.colliders[c],f=this.rayCast(b,m),f<Number.MAX_VALUE)m.distance=f,f>k?this.hits.push(m):this.hits.unshift(m),k=f;return this.hits};
M
Mr.doob 已提交
673
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.dist<Number.MAX_VALUE){c[e].distance=f.dist;c[e].faceIndex=f.faceIndex;break}e++}if(e>c.length)return null;return c[e]};
674
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)};
675 676 677 678
THREE.CollisionSystem.prototype.rayMesh=function(b,c){for(var e=this.makeRayLocal(b,c.mesh),f=Number.MAX_VALUE,m,k=0;k<c.numFaces;k++){var h=c.mesh.geometry.faces[k],n=c.mesh.geometry.vertices[h.a].position,o=c.mesh.geometry.vertices[h.b].position,u=c.mesh.geometry.vertices[h.c].position,v=h instanceof THREE.Face4?c.mesh.geometry.vertices[h.d].position:null;h instanceof THREE.Face3?(h=this.rayTriangle(e,n,o,u,f,this.collisionNormal,c.mesh),h<f&&(f=h,m=k,c.normal.copy(this.collisionNormal),c.normal.normalize())):
h instanceof THREE.Face4&&(h=this.rayTriangle(e,n,o,v,f,this.collisionNormal,c.mesh),h<f&&(f=h,m=k,c.normal.copy(this.collisionNormal),c.normal.normalize()),h=this.rayTriangle(e,o,u,v,f,this.collisionNormal,c.mesh),h<f&&(f=h,m=k,c.normal.copy(this.collisionNormal),c.normal.normalize()))}return{dist:f,faceIndex:m}};
THREE.CollisionSystem.prototype.rayTriangle=function(b,c,e,f,m,k,h){var n=THREE.CollisionSystem.__v1,o=THREE.CollisionSystem.__v2;k.set(0,0,0);n.sub(e,c);o.sub(f,e);k.cross(n,o);n=k.dot(b.direction);if(!(n<0))if(h.doubleSided||h.flipSided)k.multiplyScalar(-1),n*=-1;else return Number.MAX_VALUE;h=k.dot(c)-k.dot(b.origin);if(!(h<=0))return Number.MAX_VALUE;if(!(h>=n*m))return Number.MAX_VALUE;h/=n;n=THREE.CollisionSystem.__v3;n.copy(b.direction);n.multiplyScalar(h);n.addSelf(b.origin);Math.abs(k.x)>
Math.abs(k.y)?Math.abs(k.x)>Math.abs(k.z)?(b=n.y-c.y,k=e.y-c.y,m=f.y-c.y,n=n.z-c.z,e=e.z-c.z,f=f.z-c.z):(b=n.x-c.x,k=e.x-c.x,m=f.x-c.x,n=n.y-c.y,e=e.y-c.y,f=f.y-c.y):Math.abs(k.y)>Math.abs(k.z)?(b=n.x-c.x,k=e.x-c.x,m=f.x-c.x,n=n.z-c.z,e=e.z-c.z,f=f.z-c.z):(b=n.x-c.x,k=e.x-c.x,m=f.x-c.x,n=n.y-c.y,e=e.y-c.y,f=f.y-c.y);c=k*f-e*m;if(c==0)return Number.MAX_VALUE;c=1/c;f=(b*f-n*m)*c;if(!(f>=0))return Number.MAX_VALUE;c*=k*n-e*b;if(!(c>=0))return Number.MAX_VALUE;if(!(1-f-c>=0))return Number.MAX_VALUE;return h};
M
Mr.doob 已提交
679
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};
680 681 682
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,m=0,k=0,h=0,n=0,o=0,u=!0;e.origin.x<c.min.x?(f=c.min.x-e.origin.x,f/=e.direction.x,u=!1,h=-1):e.origin.x>c.max.x&&(f=c.max.x-e.origin.x,f/=e.direction.x,u=!1,h=1);e.origin.y<c.min.y?(m=c.min.y-e.origin.y,m/=e.direction.y,u=!1,n=-1):e.origin.y>c.max.y&&(m=c.max.y-e.origin.y,m/=e.direction.y,
u=!1,n=1);e.origin.z<c.min.z?(k=c.min.z-e.origin.z,k/=e.direction.z,u=!1,o=-1):e.origin.z>c.max.z&&(k=c.max.z-e.origin.z,k/=e.direction.z,u=!1,o=1);if(u)return-1;u=0;m>f&&(u=1,f=m);k>f&&(u=2,f=k);switch(u){case 0:n=e.origin.y+e.direction.y*f;if(n<c.min.y||n>c.max.y)return Number.MAX_VALUE;e=e.origin.z+e.direction.z*f;if(e<c.min.z||e>c.max.z)return Number.MAX_VALUE;c.normal.set(h,0,0);break;case 1:h=e.origin.x+e.direction.x*f;if(h<c.min.x||h>c.max.x)return Number.MAX_VALUE;e=e.origin.z+e.direction.z*
f;if(e<c.min.z||e>c.max.z)return Number.MAX_VALUE;c.normal.set(0,n,0);break;case 2:h=e.origin.x+e.direction.x*f;if(h<c.min.x||h>c.max.x)return Number.MAX_VALUE;n=e.origin.y+e.direction.y*f;if(n<c.min.y||n>c.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};
M
Mr.doob 已提交
683 684
THREE.CollisionSystem.prototype.raySphere=function(b,c){var e=c.center.clone().subSelf(b.origin);if(e.lengthSq<c.radiusSq)return-1;var f=e.dot(b.direction.clone());if(f<=0)return Number.MAX_VALUE;e=c.radiusSq-(e.lengthSq()-f*f);if(e>=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};
685
THREE.CollisionUtils.MeshColliderWBox=function(b){return new THREE.MeshCollider(b,THREE.CollisionUtils.MeshOBB(b))};
686
if(THREE.WebGLRenderer)THREE.AnaglyphWebGLRenderer=function(b){THREE.WebGLRenderer.call(this,b);var c=this,e=this.setSize,f=this.render,m=new THREE.Camera,k=new THREE.Camera,h=new THREE.Matrix4,n=new THREE.Matrix4,o,u,v;m.useTarget=k.useTarget=!1;m.matrixAutoUpdate=k.matrixAutoUpdate=!1;var b={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat},t=new THREE.WebGLRenderTarget(512,512,b),x=new THREE.WebGLRenderTarget(512,512,b),w=new THREE.Camera(53,1,1,1E4);w.position.z=
687
2;_material=new THREE.ShaderMaterial({uniforms:{mapLeft:{type:"t",value:0,texture:t},mapRight:{type:"t",value:1,texture:x}},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}"});
688 689
var y=new THREE.Scene;y.add(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;x.width=b;x.height=f};this.render=function(b,e){e.update(null,!0);if(o!==e.aspect||u!==e.near||v!==e.fov){o=e.aspect;u=e.near;v=e.fov;var D=e.projectionMatrix.clone(),C=125/30*0.5,F=C*u/125,G=u*Math.tan(v*Math.PI/360),N;h.n14=C;n.n14=-C;C=-G*o+F;N=G*o+F;D.n11=2*u/(N-C);D.n13=(N+C)/(N-C);m.projectionMatrix=D.clone();C=-G*o-F;N=G*o-F;D.n11=2*u/(N-C);D.n13=
(N+C)/(N-C);k.projectionMatrix=D.clone()}m.matrix=e.matrixWorld.clone().multiplySelf(n);m.update(null,!0);m.position.copy(e.position);m.near=u;m.far=e.far;f.call(c,b,m,t,!0);k.matrix=e.matrixWorld.clone().multiplySelf(h);k.update(null,!0);k.position.copy(e.position);k.near=u;k.far=e.far;f.call(c,b,k,x,!0);f.call(c,y,w)}};
690 691
if(THREE.WebGLRenderer)THREE.CrosseyedWebGLRenderer=function(b){THREE.WebGLRenderer.call(this,b);this.autoClear=!1;var c=this,e=this.setSize,f=this.render,m,k,h=new THREE.Camera,n=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);m=b/2;k=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);n.projectionMatrix=h.projectionMatrix;n.position.copy(e.position);n.target.position.copy(e.target.position);n.translateX(-c.separation);this.setViewport(0,0,m,k);f.call(c,b,h);this.setViewport(m,0,m,k);f.call(c,b,n,!1)}};