ThreeWebGL.js 92.1 KB
Newer Older
M
Mr.doob 已提交
1
// ThreeWebGL.js r35 - http://github.com/mrdoob/three.js
M
Mr.doob 已提交
2
var THREE=THREE||{};THREE.Color=function(a){this.setHex(a)};
M
Mr.doob 已提交
3
THREE.Color.prototype={autoUpdate:!0,setRGB:function(a,b,d){this.r=a;this.g=b;this.b=d;if(this.autoUpdate){this.updateHex();this.updateStyleString()}},setHSV:function(a,b,d){var f,h,n,l,q,m;if(d==0)f=h=n=0;else{l=Math.floor(a*6);q=a*6-l;a=d*(1-b);m=d*(1-b*q);b=d*(1-b*(1-q));switch(l){case 1:f=m;h=d;n=a;break;case 2:f=a;h=d;n=b;break;case 3:f=a;h=m;n=d;break;case 4:f=b;h=a;n=d;break;case 5:f=d;h=a;n=m;break;case 6:case 0:f=d;h=b;n=a}}this.r=f;this.g=h;this.b=n;if(this.autoUpdate){this.updateHex();
4
this.updateStyleString()}},setHex:function(a){this.hex=~~a&16777215;if(this.autoUpdate){this.updateRGB();this.updateStyleString()}},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGB:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},updateStyleString:function(){this.__styleString="rgb("+~~(this.r*255)+","+~~(this.g*255)+","+~~(this.b*255)+")"},clone:function(){return new THREE.Color(this.hex)}};
5 6 7 8 9 10 11 12 13 14
THREE.Vector2=function(a,b){this.set(a||0,b||0)};
THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.set(a.x,a.y);return this},addSelf:function(a){this.set(this.x+a.x,this.y+a.y);return this},add:function(a,b){this.set(a.x+b.x,a.y+b.y);return this},subSelf:function(a){this.set(this.x-a.x,this.y-a.y);return this},sub:function(a,b){this.set(a.x-b.x,a.y-b.y);return this},multiplyScalar:function(a){this.set(this.x*a,this.y*a);return this},negate:function(){this.set(-this.x,-this.y);return this},unit:function(){this.multiplyScalar(1/
this.length());return this},length:function(){return Math.sqrt(this.lengthSq())},lengthSq:function(){return this.x*this.x+this.y*this.y},clone:function(){return new THREE.Vector2(this.x,this.y)}};THREE.Vector3=function(a,b,d){this.set(a||0,b||0,d||0)};
THREE.Vector3.prototype={set:function(a,b,d){this.x=a;this.y=b;this.z=d;return this},copy:function(a){this.set(a.x,a.y,a.z);return this},add:function(a,b){this.set(a.x+b.x,a.y+b.y,a.z+b.z);return this},addSelf:function(a){this.set(this.x+a.x,this.y+a.y,this.z+a.z);return this},addScalar:function(a){this.set(this.x+a,this.y+a,this.z+a);return this},sub:function(a,b){this.set(a.x-b.x,a.y-b.y,a.z-b.z);return this},subSelf:function(a){this.set(this.x-a.x,this.y-a.y,this.z-a.z);return this},cross:function(a,
b){this.set(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);return this},crossSelf:function(a){var b=this.x,d=this.y,f=this.z;this.set(d*a.z-f*a.y,f*a.x-b*a.z,b*a.y-d*a.x);return this},multiply:function(a,b){this.set(a.x*b.x,a.y*b.y,a.z*b.z);return this},multiplySelf:function(a){this.set(this.x*a.x,this.y*a.y,this.z*a.z);return this},multiplyScalar:function(a){this.set(this.x*a,this.y*a,this.z*a);return this},divideSelf:function(a){this.set(this.x/a.x,this.y/a.y,this.z/a.z);return this},divideScalar:function(a){this.set(this.x/
a,this.y/a,this.z/a);return this},negate:function(){this.set(-this.x,-this.y,-this.z);return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return b*b+d*d+a*a},length:function(){return Math.sqrt(this.lengthSq())},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},lengthManhattan:function(){return this.x+this.y+this.z},normalize:function(){var a=
this.length();a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this},setPositionFromMatrix:function(a){this.x=a.n14;this.y=a.n24;this.z=a.n34},setRotationFromMatrix:function(a){this.y=Math.asin(a.n13);var b=Math.cos(this.y);if(Math.abs(b)>1.0E-5){this.x=Math.atan2(-a.n23/b,a.n33/b);this.z=Math.atan2(-a.n13/b,a.n11/b)}else{this.x=0;this.z=Math.atan2(a.n21,a.n22)}},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<1.0E-4&&Math.abs(this.y)<
1.0E-4&&Math.abs(this.z)<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)}};THREE.Vector4=function(a,b,d,f){this.set(a||0,b||0,d||0,f||1)};
THREE.Vector4.prototype={set:function(a,b,d,f){this.x=a;this.y=b;this.z=d;this.w=f;return this},copy:function(a){this.set(a.x,a.y,a.z,a.w||1);return this},add:function(a,b){this.set(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);return this},addSelf:function(a){this.set(this.x+a.x,this.y+a.y,this.z+a.z,this.w+a.w);return this},sub:function(a,b){this.set(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);return this},subSelf:function(a){this.set(this.x-a.x,this.y-a.y,this.z-a.z,this.w-a.w);return this},multiplyScalar:function(a){this.set(this.x*
a,this.y*a,this.z*a,this.w*a);return this},divideScalar:function(a){this.set(this.x/a,this.y/a,this.z/a,this.w/a);return this},lerpSelf:function(a,b){this.set(this.x+(a.x-this.x)*b,this.y+(a.y-this.y)*b,this.z+(a.z-this.z)*b,this.w+(a.w-this.w)*b)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)}};THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
M
Mr.doob 已提交
15 16 17 18 19 20
THREE.Ray.prototype={intersectScene:function(a){var b,d,f=a.objects,h=[];a=0;for(b=f.length;a<b;a++){d=f[a];d instanceof THREE.Mesh&&(h=h.concat(this.intersectObject(d)))}h.sort(function(n,l){return n.distance-l.distance});return h},intersectObject:function(a){function b(L,M,V,X){X=X.clone().subSelf(M);V=V.clone().subSelf(M);var ca=L.clone().subSelf(M);L=X.dot(X);M=X.dot(V);X=X.dot(ca);var aa=V.dot(V);V=V.dot(ca);ca=1/(L*aa-M*M);aa=(aa*X-M*V)*ca;L=(L*V-M*X)*ca;return aa>0&&L>0&&aa+L<1}var d,f,h,n,
l,q,m,w,A,y,D,E=a.geometry,F=E.vertices,H=[];d=0;for(f=E.faces.length;d<f;d++){h=E.faces[d];y=this.origin.clone();D=this.direction.clone();m=a.matrixWorld;n=m.multiplyVector3(F[h.a].position.clone());l=m.multiplyVector3(F[h.b].position.clone());q=m.multiplyVector3(F[h.c].position.clone());m=h instanceof THREE.Face4?m.multiplyVector3(F[h.d].position.clone()):null;w=a.matrixRotationWorld.multiplyVector3(h.normal.clone());A=D.dot(w);if(A<0){w=w.dot((new THREE.Vector3).sub(n,y))/A;y=y.addSelf(D.multiplyScalar(w));
if(h instanceof THREE.Face3){if(b(y,n,l,q)){h={distance:this.origin.distanceTo(y),point:y,face:h,object:a};H.push(h)}}else if(h instanceof THREE.Face4&&(b(y,n,l,m)||b(y,l,q,m))){h={distance:this.origin.distanceTo(y),point:y,face:h,object:a};H.push(h)}}}return H}};
THREE.Rectangle=function(){function a(){n=f-b;l=h-d}var b,d,f,h,n,l,q=!0;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return n};this.getHeight=function(){return l};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return f};this.getBottom=function(){return h};this.set=function(m,w,A,y){q=!1;b=m;d=w;f=A;h=y;a()};this.addPoint=function(m,w){if(q){q=!1;b=m;d=w;f=m;h=w}else{b=b<m?b:m;d=d<w?d:w;f=f>m?f:m;h=h>w?h:w}a()};
this.add3Points=function(m,w,A,y,D,E){if(q){q=!1;b=m<A?m<D?m:D:A<D?A:D;d=w<y?w<E?w:E:y<E?y:E;f=m>A?m>D?m:D:A>D?A:D;h=w>y?w>E?w:E:y>E?y:E}else{b=m<A?m<D?m<b?m:b:D<b?D:b:A<D?A<b?A:b:D<b?D:b;d=w<y?w<E?w<d?w:d:E<d?E:d:y<E?y<d?y:d:E<d?E:d;f=m>A?m>D?m>f?m:f:D>f?D:f:A>D?A>f?A:f:D>f?D:f;h=w>y?w>E?w>h?w:h:E>h?E:h:y>E?y>h?y:h:E>h?E:h}a()};this.addRectangle=function(m){if(q){q=!1;b=m.getLeft();d=m.getTop();f=m.getRight();h=m.getBottom()}else{b=b<m.getLeft()?b:m.getLeft();d=d<m.getTop()?d:m.getTop();f=f>m.getRight()?
f:m.getRight();h=h>m.getBottom()?h:m.getBottom()}a()};this.inflate=function(m){b-=m;d-=m;f+=m;h+=m;a()};this.minSelf=function(m){b=b>m.getLeft()?b:m.getLeft();d=d>m.getTop()?d:m.getTop();f=f<m.getRight()?f:m.getRight();h=h<m.getBottom()?h:m.getBottom();a()};this.instersects=function(m){return Math.min(f,m.getRight())-Math.max(b,m.getLeft())>=0&&Math.min(h,m.getBottom())-Math.max(d,m.getTop())>=0};this.empty=function(){q=!0;h=f=d=b=0;a()};this.isEmpty=function(){return q}};
21
THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
M
Mr.doob 已提交
22 23 24
THREE.Matrix4=function(a,b,d,f,h,n,l,q,m,w,A,y,D,E,F,H){this.set(a||1,b||0,d||0,f||0,h||0,n||1,l||0,q||0,m||0,w||0,A||1,y||0,D||0,E||0,F||0,H||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
THREE.Matrix4.prototype={set:function(a,b,d,f,h,n,l,q,m,w,A,y,D,E,F,H){this.n11=a;this.n12=b;this.n13=d;this.n14=f;this.n21=h;this.n22=n;this.n23=l;this.n24=q;this.n31=m;this.n32=w;this.n33=A;this.n34=y;this.n41=D;this.n42=E;this.n43=F;this.n44=H;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(a){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a,b,d){var f=THREE.Matrix4.__v1,
h=THREE.Matrix4.__v2,n=THREE.Matrix4.__v3;n.sub(a,b).normalize();f.cross(d,n).normalize();h.cross(n,f).normalize();this.n11=f.x;this.n12=h.x;this.n13=n.x;this.n21=f.y;this.n22=h.y;this.n23=n.y;this.n31=f.z;this.n32=h.z;this.n33=n.z;return this},multiplyVector3:function(a){var b=a.x,d=a.y,f=a.z,h=1/(this.n41*b+this.n42*d+this.n43*f+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*f+this.n14)*h;a.y=(this.n21*b+this.n22*d+this.n23*f+this.n24)*h;a.z=(this.n31*b+this.n32*d+this.n33*f+this.n34)*h;return a},
25 26 27 28 29 30 31 32 33 34 35 36
multiplyVector4:function(a){var b=a.x,d=a.y,f=a.z,h=a.w;a.x=this.n11*b+this.n12*d+this.n13*f+this.n14*h;a.y=this.n21*b+this.n22*d+this.n23*f+this.n24*h;a.z=this.n31*b+this.n32*d+this.n33*f+this.n34*h;a.w=this.n41*b+this.n42*d+this.n43*f+this.n44*h;return a},rotateAxis:function(a){var b=a.x,d=a.y,f=a.z;a.x=b*this.n11+d*this.n12+f*this.n13;a.y=b*this.n21+d*this.n22+f*this.n23;a.z=b*this.n31+d*this.n32+f*this.n33;a.normalize();return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+
this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,f=a.n12,h=a.n13,n=a.n14,l=a.n21,q=a.n22,m=a.n23,w=a.n24,A=a.n31,y=a.n32,D=a.n33,E=a.n34,F=a.n41,H=a.n42,L=a.n43,M=a.n44,V=b.n11,X=b.n12,ca=b.n13,aa=b.n14,Y=b.n21,fa=b.n22,c=b.n23,na=b.n24,la=b.n31,oa=b.n32,pa=b.n33,qa=b.n34;this.n11=d*V+f*Y+h*
la;this.n12=d*X+f*fa+h*oa;this.n13=d*ca+f*c+h*pa;this.n14=d*aa+f*na+h*qa+n;this.n21=l*V+q*Y+m*la;this.n22=l*X+q*fa+m*oa;this.n23=l*ca+q*c+m*pa;this.n24=l*aa+q*na+m*qa+w;this.n31=A*V+y*Y+D*la;this.n32=A*X+y*fa+D*oa;this.n33=A*ca+y*c+D*pa;this.n34=A*aa+y*na+D*qa+E;this.n41=F*V+H*Y+L*la;this.n42=F*X+H*fa+L*oa;this.n43=F*ca+H*c+L*pa;this.n44=F*aa+H*na+L*qa+M;return this},multiplyToArray:function(a,b,d){this.multiply(a,b);d[0]=this.n11;d[1]=this.n21;d[2]=this.n31;d[3]=this.n41;d[4]=this.n12;d[5]=this.n22;
d[6]=this.n32;d[7]=this.n42;d[8]=this.n13;d[9]=this.n23;d[10]=this.n33;d[11]=this.n43;d[12]=this.n14;d[13]=this.n24;d[14]=this.n34;d[15]=this.n44;return this},multiplySelf:function(a){this.multiply(this,a);return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,d=
this.n13,f=this.n14,h=this.n21,n=this.n22,l=this.n23,q=this.n24,m=this.n31,w=this.n32,A=this.n33,y=this.n34,D=this.n41,E=this.n42,F=this.n43,H=this.n44;return f*l*w*D-d*q*w*D-f*n*A*D+b*q*A*D+d*n*y*D-b*l*y*D-f*l*m*E+d*q*m*E+f*h*A*E-a*q*A*E-d*h*y*E+a*l*y*E+f*n*m*F-b*q*m*F-f*h*w*F+a*q*w*F+b*h*y*F-a*n*y*F-d*n*m*H+b*l*m*H+d*h*w*H-a*l*w*H-b*h*A*H+a*n*A*H},transpose:function(){var a;a=this.n21;this.n21=this.n12;this.n12=a;a=this.n31;this.n31=this.n13;this.n13=a;a=this.n32;this.n32=this.n23;this.n23=a;a=
this.n41;this.n41=this.n14;this.n14=a;a=this.n42;this.n42=this.n24;this.n24=a;a=this.n43;this.n43=this.n34;this.n43=a;return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){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(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;
a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArrayOffset:function(a,b){a[b]=this.n11;a[b+1]=this.n21;a[b+2]=this.n31;a[b+3]=this.n41;a[b+4]=this.n12;a[b+5]=this.n22;a[b+6]=this.n32;a[b+7]=this.n42;a[b+8]=this.n13;a[b+9]=this.n23;a[b+10]=this.n33;a[b+11]=this.n43;a[b+12]=this.n14;a[b+13]=this.n24;a[b+14]=this.n34;a[b+15]=this.n44;return a},setTranslation:function(a,b,d){this.set(1,0,0,a,0,1,0,b,0,0,1,d,0,0,0,1);return this},setScale:function(a,b,d){this.set(a,0,0,
0,0,b,0,0,0,0,d,0,0,0,0,1);return this},setRotationX:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},setRotationY:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},setRotationZ:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},setRotationAxis:function(a,b){var d=Math.cos(b),f=Math.sin(b),h=1-d,n=a.x,l=a.y,q=a.z,m=h*n,w=h*l;this.set(m*n+d,m*l-f*q,m*
q+f*l,0,m*l+f*q,w*l+d,w*q-f*n,0,m*q-f*l,w*q+f*n,h*q*q+d,0,0,0,0,1);return this},setPosition:function(a){this.n14=a.x;this.n24=a.y;this.n34=a.z;return this},setRotationFromEuler:function(a){var b=a.x,d=a.y,f=a.z;a=Math.cos(b);b=Math.sin(b);var h=Math.cos(d);d=Math.sin(d);var n=Math.cos(f);f=Math.sin(f);var l=a*d,q=b*d;this.n11=h*n;this.n12=-h*f;this.n13=d;this.n21=q*n+a*f;this.n22=-q*f+a*n;this.n23=-b*h;this.n31=-l*n+b*f;this.n32=l*f+b*n;this.n33=a*h;return this},setRotationFromQuaternion:function(a){var b=
a.x,d=a.y,f=a.z,h=a.w,n=b+b,l=d+d,q=f+f;a=b*n;var m=b*l;b*=q;var w=d*l;d*=q;f*=q;n*=h;l*=h;h*=q;this.n11=1-(w+f);this.n12=m-h;this.n13=b+l;this.n21=m+h;this.n22=1-(a+f);this.n23=d-n;this.n31=b-l;this.n32=d+n;this.n33=1-(a+w);return this},scale:function(a){var b=a.x,d=a.y;a=a.z;this.n11*=b;this.n12*=d;this.n13*=a;this.n21*=b;this.n22*=d;this.n23*=a;this.n31*=b;this.n32*=d;this.n33*=a;this.n41*=b;this.n42*=d;this.n43*=a;return this},extractPosition:function(a){this.n14=a.n14;this.n24=a.n24;this.n34=
a.n34},extractRotation:function(a,b){var d=1/b.x,f=1/b.y,h=1/b.z;this.n11=a.n11*d;this.n21=a.n21*d;this.n31=a.n31*d;this.n12=a.n12*f;this.n22=a.n22*f;this.n32=a.n32*f;this.n13=a.n13*h;this.n23=a.n23*h;this.n33=a.n33*h}};
M
Mr.doob 已提交
37 38 39 40 41
THREE.Matrix4.makeInvert=function(a,b){var d=a.n11,f=a.n12,h=a.n13,n=a.n14,l=a.n21,q=a.n22,m=a.n23,w=a.n24,A=a.n31,y=a.n32,D=a.n33,E=a.n34,F=a.n41,H=a.n42,L=a.n43,M=a.n44;b===undefined&&(b=new THREE.Matrix4);b.n11=m*E*H-w*D*H+w*y*L-q*E*L-m*y*M+q*D*M;b.n12=n*D*H-h*E*H-n*y*L+f*E*L+h*y*M-f*D*M;b.n13=h*w*H-n*m*H+n*q*L-f*w*L-h*q*M+f*m*M;b.n14=n*m*y-h*w*y-n*q*D+f*w*D+h*q*E-f*m*E;b.n21=w*D*F-m*E*F-w*A*L+l*E*L+m*A*M-l*D*M;b.n22=h*E*F-n*D*F+n*A*L-d*E*L-h*A*M+d*D*M;b.n23=n*m*F-h*w*F-n*l*L+d*w*L+h*l*M-d*m*M;
b.n24=h*w*A-n*m*A+n*l*D-d*w*D-h*l*E+d*m*E;b.n31=q*E*F-w*y*F+w*A*H-l*E*H-q*A*M+l*y*M;b.n32=n*y*F-f*E*F-n*A*H+d*E*H+f*A*M-d*y*M;b.n33=h*w*F-n*q*F+n*l*H-d*w*H-f*l*M+d*q*M;b.n34=n*q*A-f*w*A-n*l*y+d*w*y+f*l*E-d*q*E;b.n41=m*y*F-q*D*F-m*A*H+l*D*H+q*A*L-l*y*L;b.n42=f*D*F-h*y*F+h*A*H-d*D*H-f*A*L+d*y*L;b.n43=h*q*F-f*m*F-h*l*H+d*m*H+f*l*L-d*q*L;b.n44=f*m*A-h*q*A+h*l*y-d*m*y-f*l*D+d*q*D;b.multiplyScalar(1/a.determinant());return b};
THREE.Matrix4.makeInvert3x3=function(a){var b=a.m33,d=b.m,f=a.n33*a.n22-a.n32*a.n23,h=-a.n33*a.n21+a.n31*a.n23,n=a.n32*a.n21-a.n31*a.n22,l=-a.n33*a.n12+a.n32*a.n13,q=a.n33*a.n11-a.n31*a.n13,m=-a.n32*a.n11+a.n31*a.n12,w=a.n23*a.n12-a.n22*a.n13,A=-a.n23*a.n11+a.n21*a.n13,y=a.n22*a.n11-a.n21*a.n12;a=a.n11*f+a.n21*l+a.n31*w;if(a==0)throw"matrix not invertible";a=1/a;d[0]=a*f;d[1]=a*h;d[2]=a*n;d[3]=a*l;d[4]=a*q;d[5]=a*m;d[6]=a*w;d[7]=a*A;d[8]=a*y;return b};
THREE.Matrix4.makeFrustum=function(a,b,d,f,h,n){var l;l=new THREE.Matrix4;l.n11=2*h/(b-a);l.n12=0;l.n13=(b+a)/(b-a);l.n14=0;l.n21=0;l.n22=2*h/(f-d);l.n23=(f+d)/(f-d);l.n24=0;l.n31=0;l.n32=0;l.n33=-(n+h)/(n-h);l.n34=-2*n*h/(n-h);l.n41=0;l.n42=0;l.n43=-1;l.n44=0;return l};THREE.Matrix4.makePerspective=function(a,b,d,f){var h;a=d*Math.tan(a*Math.PI/360);h=-a;return THREE.Matrix4.makeFrustum(h*b,a*b,h,a,d,f)};
THREE.Matrix4.makeOrtho=function(a,b,d,f,h,n){var l,q,m,w;l=new THREE.Matrix4;q=b-a;m=d-f;w=n-h;l.n11=2/q;l.n12=0;l.n13=0;l.n14=-((b+a)/q);l.n21=0;l.n22=2/m;l.n23=0;l.n24=-((d+f)/m);l.n31=0;l.n32=0;l.n33=-2/w;l.n34=-((n+h)/w);l.n41=0;l.n42=0;l.n43=0;l.n44=1;return l};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
42
THREE.Object3D=function(){this.parent=undefined;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixAutoUpdate=!0;this.matrixWorldNeedsUpdate=!0;this.quaternion=new THREE.Quaternion;this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=
M
Mr.doob 已提交
43 44 45 46 47 48 49 50
!0;this._vector=new THREE.Vector3};
THREE.Object3D.prototype={translate:function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a))},translateX:function(a){this.translate(a,this._vector.set(1,0,0))},translateY:function(a){this.translate(a,this._vector.set(0,1,0))},translateZ:function(a){this.translate(a,this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(this.position,a,this.up);this.rotationAutoUpdate&&this.rotation.setRotationFromMatrix(this.matrix)},addChild:function(a){if(this.children.indexOf(a)===-1){a.parent!==
undefined&&a.parent.removeChild(a);a.parent=this;this.children.push(a);for(var b=this;b instanceof THREE.Scene===!1&&b!==undefined;)b=b.parent;b!==undefined&&b.addChildRecurse(a)}},removeChild:function(a){var b=this.children.indexOf(a);if(b!==-1){a.parent=undefined;this.children.splice(b,1)}},updateMatrix:function(){this.matrix.setPosition(this.position);this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation);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))}return!0},update:function(a,b,d){if(this.visible){this.matrixAutoUpdate&&(b|=this.updateMatrix());if(b||this.matrixWorldNeedsUpdate){a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale);this.matrixWorldNeedsUpdate=!1;b=!0}a=0;for(var f=this.children.length;a<f;a++)this.children[a].update(this.matrixWorld,
b,d)}}};THREE.Quaternion=function(a,b,d,f){this.set(a||0,b||0,d||0,f!==undefined?f:1)};
THREE.Quaternion.prototype={set:function(a,b,d,f){this.x=a;this.y=b;this.z=d;this.w=f;return this},setFromEuler:function(a){var b=0.5*Math.PI/360,d=a.x*b,f=a.y*b,h=a.z*b;a=Math.cos(f);f=Math.sin(f);b=Math.cos(-h);h=Math.sin(-h);var n=Math.cos(d);d=Math.sin(d);var l=a*b,q=f*h;this.w=l*n-q*d;this.x=l*d+q*n;this.y=f*b*n+a*h*d;this.z=a*h*n-f*b*d;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 a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a==0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x*=a;this.y*=a;this.z*=a;this.w*=a}return this},multiplySelf:function(a){var b=this.x,d=this.y,f=this.z,h=this.w,n=a.x,l=a.y,q=a.z;a=a.w;this.x=b*a+h*n+d*q-f*l;this.y=d*a+h*l+f*n-b*q;this.z=f*a+h*q+b*l-d*n;this.w=h*a-b*n-d*l-f*q;return this},
multiplyVector3:function(a,b){b||(b=a);var d=a.x,f=a.y,h=a.z,n=this.x,l=this.y,q=this.z,m=this.w,w=m*d+l*h-q*f,A=m*f+q*d-n*h,y=m*h+n*f-l*d;d=-n*d-l*f-q*h;b.x=w*m+d*-n+A*-q-y*-l;b.y=A*m+d*-l+y*-n-w*-q;b.z=y*m+d*-q+w*-l-A*-n;return b}};
51
THREE.Quaternion.slerp=function(a,b,d,f){var h=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(Math.abs(h)>=1){d.w=a.w;d.x=a.x;d.y=a.y;d.z=a.z;return d}var n=Math.acos(h),l=Math.sqrt(1-h*h);if(Math.abs(l)<0.0010){d.w=0.5*(a.w+b.w);d.x=0.5*(a.x+b.x);d.y=0.5*(a.y+b.y);d.z=0.5*(a.z+b.z);return d}h=Math.sin((1-f)*n)/l;f=Math.sin(f*n)/l;d.w=a.w*h+b.w*f;d.x=a.x*h+b.x*f;d.y=a.y*h+b.y*f;d.z=a.z*h+b.z*f;return d};
52
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=!0};
M
Mr.doob 已提交
53
THREE.Face3=function(a,b,d,f,h){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.materials=h instanceof Array?h:[h]};THREE.Face4=function(a,b,d,f,h,n){this.a=a;this.b=b;this.c=d;this.d=f;this.centroid=new THREE.Vector3;this.normal=h instanceof THREE.Vector3?h:new THREE.Vector3;this.vertexNormals=h instanceof Array?h:[];this.materials=n instanceof Array?n:[n]};
54 55
THREE.UV=function(a,b){this.set(a||0,b||0)};THREE.UV.prototype={set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.set(a.u,a.v);return this}};THREE.Geometry=function(){this.id="Geometry"+THREE.GeometryIdCounter++;this.vertices=[];this.faces=[];this.uvs=[];this.uvs2=[];this.colors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.hasTangents=!1};
THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
M
Mr.doob 已提交
56 57
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,d,f,h,n,l,q=new THREE.Vector3,m=new THREE.Vector3;f=0;for(h=this.vertices.length;f<h;f++){n=this.vertices[f];n.normal.set(0,0,0)}f=0;for(h=this.faces.length;f<h;f++){n=this.faces[f];if(a&&n.vertexNormals.length){q.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)q.addSelf(n.vertexNormals[b]);q.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];l=this.vertices[n.c];q.sub(l.position,
d.position);m.sub(b.position,d.position);q.crossSelf(m)}q.isZero()||q.normalize();n.normal.copy(q)}},computeVertexNormals:function(){var a,b,d,f;if(this.__tmpVertices==undefined){f=this.__tmpVertices=Array(this.vertices.length);a=0;for(b=this.vertices.length;a<b;a++)f[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];if(d instanceof THREE.Face3)d.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(d instanceof THREE.Face4)d.vertexNormals=[new THREE.Vector3,
58
new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{f=this.__tmpVertices;a=0;for(b=this.vertices.length;a<b;a++)f[a].set(0,0,0)}a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];if(d instanceof THREE.Face3){f[d.a].addSelf(d.normal);f[d.b].addSelf(d.normal);f[d.c].addSelf(d.normal)}else if(d instanceof THREE.Face4){f[d.a].addSelf(d.normal);f[d.b].addSelf(d.normal);f[d.c].addSelf(d.normal);f[d.d].addSelf(d.normal)}}a=0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<
M
Mr.doob 已提交
59 60
b;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0].copy(f[d.a]);d.vertexNormals[1].copy(f[d.b]);d.vertexNormals[2].copy(f[d.c])}else if(d instanceof THREE.Face4){d.vertexNormals[0].copy(f[d.a]);d.vertexNormals[1].copy(f[d.b]);d.vertexNormals[2].copy(f[d.c]);d.vertexNormals[3].copy(f[d.d])}}},computeTangents:function(){function a(qa,za,Aa,va,Da,Ea,Fa){n=qa.vertices[za].position;l=qa.vertices[Aa].position;q=qa.vertices[va].position;m=h[Da];w=h[Ea];A=h[Fa];y=l.x-n.x;D=q.x-n.x;E=l.y-
n.y;F=q.y-n.y;H=l.z-n.z;L=q.z-n.z;M=w.u-m.u;V=A.u-m.u;X=w.v-m.v;ca=A.v-m.v;aa=1/(M*ca-V*X);c.set((ca*y-X*D)*aa,(ca*E-X*F)*aa,(ca*H-X*L)*aa);na.set((M*D-V*y)*aa,(M*F-V*E)*aa,(M*L-V*H)*aa);Y[za].addSelf(c);Y[Aa].addSelf(c);Y[va].addSelf(c);fa[za].addSelf(na);fa[Aa].addSelf(na);fa[va].addSelf(na)}var b,d,f,h,n,l,q,m,w,A,y,D,E,F,H,L,M,V,X,ca,aa,Y=[],fa=[],c=new THREE.Vector3,na=new THREE.Vector3,la=new THREE.Vector3,oa=new THREE.Vector3,pa=new THREE.Vector3;b=0;for(d=this.vertices.length;b<d;b++){Y[b]=
61 62
new THREE.Vector3;fa[b]=new THREE.Vector3}b=0;for(d=this.faces.length;b<d;b++){f=this.faces[b];h=this.uvs[b];if(f instanceof THREE.Face3){a(this,f.a,f.b,f.c,0,1,2);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2])}else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.c,0,1,2);a(this,f.a,f.b,f.d,0,1,3);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);
this.vertices[f.c].normal.copy(f.vertexNormals[2]);this.vertices[f.d].normal.copy(f.vertexNormals[3])}}b=0;for(d=this.vertices.length;b<d;b++){pa.copy(this.vertices[b].normal);f=Y[b];la.copy(f);la.subSelf(pa.multiplyScalar(pa.dot(f))).normalize();oa.cross(this.vertices[b].normal,f);f=oa.dot(fa[b]);f=f<0?-1:1;this.vertices[b].tangent.set(la.x,la.y,la.z,f)}this.hasTangents=!0},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
63 64
y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,d=this.vertices.length;b<d;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<
this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,d=this.vertices.length;b<d;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}}};THREE.GeometryIdCounter=0;
M
Mr.doob 已提交
65 66
THREE.Camera=function(a,b,d,f,h){THREE.Object3D.call(this);this.fov=a||50;this.aspect=b||1;this.near=d||0.1;this.far=f||2E3;this.target=h||new THREE.Object3D;this.useTarget=!0;this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=null;this.updateProjectionMatrix()};THREE.Camera.prototype=new THREE.Object3D;THREE.Camera.prototype.constructor=THREE.Camera;THREE.Camera.prototype.supr=THREE.Object3D.prototype;
THREE.Camera.prototype.translate=function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a));this.target.position.addSelf(b.multiplyScalar(a))};THREE.Camera.prototype.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};
67 68 69
THREE.Camera.prototype.update=function(a,b,d){if(this.useTarget){this.matrix.lookAt(this.position,this.target.position,this.up);this.matrix.setPosition(this.position);a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix);THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse);b=!0}else{this.matrixAutoUpdate&&(b|=this.updateMatrix());if(b||this.matrixWorldNeedsUpdate){a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=
!1;b=!0;THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse)}}for(a=0;a<this.children.length;a++)this.children[a].update(this.matrixWorld,b,d)};THREE.Light=function(a){THREE.Object3D.call(this);this.color=new THREE.Color(a)};THREE.Light.prototype=new THREE.Object3D;THREE.Light.prototype.constructor=THREE.Light;THREE.Light.prototype.supr=THREE.Object3D.prototype;THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;
THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;
70
THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.BillboardBlending=3;THREE.ReverseSubtractiveBlending=4;THREE.MaterialCounter={value:0};THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
THREE.LineBasicMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.blending=THREE.NormalBlending;this.depthTest=!0;this.linewidth=1;this.linejoin=this.linecap="round";this.vertexColors=!1;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.depthTest!==undefined)this.depthTest=a.depthTest;if(a.linewidth!==undefined)this.linewidth=
a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin;if(a.vertexColors!==undefined)this.vertexColors=a.vertexColors}};
THREE.MeshBasicMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.envMap=this.lightMap=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.fog=!0;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depthTest=!0;this.wireframe=!1;this.wireframeLinewidth=1;this.wireframeLinejoin=this.wireframeLinecap="round";this.vertexColors=!1;this.skinning=!1;if(a){a.color!==undefined&&
this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.map!==undefined)this.map=a.map;if(a.lightMap!==undefined)this.lightMap=a.lightMap;if(a.envMap!==undefined)this.envMap=a.envMap;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refractionRatio!==undefined)this.refractionRatio=a.refractionRatio;if(a.fog!==undefined)this.fog=a.fog;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=
a.blending;if(a.depthTest!==undefined)this.depthTest=a.depthTest;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframeLinewidth!==undefined)this.wireframeLinewidth=a.wireframeLinewidth;if(a.wireframeLinecap!==undefined)this.wireframeLinecap=a.wireframeLinecap;if(a.wireframeLinejoin!==undefined)this.wireframeLinejoin=a.wireframeLinejoin;if(a.vertexColors!==undefined)this.vertexColors=a.vertexColors;if(a.skinning!==undefined)this.skinning=a.skinning}};
THREE.MeshLambertMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.envMap=this.lightMap=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.fog=!0;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depthTest=!0;this.wireframe=!1;this.wireframeLinewidth=1;this.wireframeLinejoin=this.wireframeLinecap="round";this.vertexColors=!1;this.skinning=!1;if(a){a.color!==undefined&&
this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.map!==undefined)this.map=a.map;if(a.lightMap!==undefined)this.lightMap=a.lightMap;if(a.envMap!==undefined)this.envMap=a.envMap;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refractionRatio!==undefined)this.refractionRatio=a.refractionRatio;if(a.fog!==undefined)this.fog=a.fog;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=
a.blending;if(a.depthTest!==undefined)this.depthTest=a.depthTest;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframeLinewidth!==undefined)this.wireframeLinewidth=a.wireframeLinewidth;if(a.wireframeLinecap!==undefined)this.wireframeLinecap=a.wireframeLinecap;if(a.wireframeLinejoin!==undefined)this.wireframeLinejoin=a.wireframeLinejoin;if(a.vertexColors!==undefined)this.vertexColors=a.vertexColors;if(a.skinning!==undefined)this.skinning=a.skinning}};
THREE.MeshPhongMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.color=new THREE.Color(16777215);this.ambient=new THREE.Color(328965);this.specular=new THREE.Color(1118481);this.shininess=30;this.opacity=1;this.envMap=this.lightMap=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.fog=!0;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depthTest=!0;this.wireframe=!1;this.wireframeLinewidth=1;this.wireframeLinejoin=
this.wireframeLinecap="round";this.vertexColors=!1;this.skinning=!1;if(a){if(a.color!==undefined)this.color=new THREE.Color(a.color);if(a.ambient!==undefined)this.ambient=new THREE.Color(a.ambient);if(a.specular!==undefined)this.specular=new THREE.Color(a.specular);if(a.shininess!==undefined)this.shininess=a.shininess;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.lightMap!==undefined)this.lightMap=a.lightMap;if(a.map!==undefined)this.map=a.map;if(a.envMap!==undefined)this.envMap=a.envMap;if(a.combine!==
undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refractionRatio!==undefined)this.refractionRatio=a.refractionRatio;if(a.fog!==undefined)this.fog=a.fog;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.depthTest!==undefined)this.depthTest=a.depthTest;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframeLinewidth!==undefined)this.wireframeLinewidth=a.wireframeLinewidth;if(a.wireframeLinecap!==
undefined)this.wireframeLinecap=a.wireframeLinecap;if(a.wireframeLinejoin!==undefined)this.wireframeLinejoin=a.wireframeLinejoin;if(a.vertexColors!==undefined)this.vertexColors=a.vertexColors;if(a.skinning!==undefined)this.skinning=a.skinning}};
THREE.MeshDepthMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depthTest=!0;this.wireframe=!1;this.wireframeLinewidth=1;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.depthTest!==undefined)this.depthTest=a.depthTest;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframeLinewidth!==
undefined)this.wireframeLinewidth=a.wireframeLinewidth}};
THREE.MeshNormalMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.opacity=1;this.shading=THREE.FlatShading;this.blending=THREE.NormalBlending;this.depthTest=!0;this.wireframe=!1;this.wireframeLinewidth=1;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.depthTest!==undefined)this.depthTest=a.depthTest;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframeLinewidth!==
undefined)this.wireframeLinewidth=a.wireframeLinewidth}};THREE.MeshFaceMaterial=function(){};
THREE.MeshShaderMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.vertexShader=this.fragmentShader="void main() {}";this.uniforms={};this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depthTest=!0;this.wireframe=!1;this.wireframeLinewidth=1;this.wireframeLinejoin=this.wireframeLinecap="round";this.vertexColors=!1;this.skinning=!1;if(a){if(a.fragmentShader!==undefined)this.fragmentShader=a.fragmentShader;if(a.vertexShader!==undefined)this.vertexShader=
a.vertexShader;if(a.uniforms!==undefined)this.uniforms=a.uniforms;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.depthTest!==undefined)this.depthTest=a.depthTest;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframeLinewidth!==undefined)this.wireframeLinewidth=a.wireframeLinewidth;if(a.wireframeLinecap!==undefined)this.wireframeLinecap=a.wireframeLinecap;if(a.wireframeLinejoin!==
undefined)this.wireframeLinejoin=a.wireframeLinejoin;if(a.vertexColors!==undefined)this.vertexColors=a.vertexColors;if(a.skinning!==undefined)this.skinning=a.skinning}};
THREE.ParticleBasicMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.map=null;this.size=1;this.blending=THREE.NormalBlending;this.depthTest=!0;this.offset=new THREE.Vector2;this.vertexColors=!1;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.map!==undefined)this.map=a.map;if(a.size!==undefined)this.size=a.size;if(a.blending!==undefined)this.blending=a.blending;if(a.depthTest!==
undefined)this.depthTest=a.depthTest;if(a.vertexColors!==undefined)this.vertexColors=a.vertexColors}};THREE.ParticleCircleMaterial=function(a){this.id=THREE.MaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}};
M
Mr.doob 已提交
92
THREE.Texture=function(a,b,d,f,h,n){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrapS=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrapT=f!==undefined?f:THREE.ClampToEdgeWrapping;this.magFilter=h!==undefined?h:THREE.LinearFilter;this.minFilter=n!==undefined?n:THREE.LinearMipMapLinearFilter;this.needsUpdate=!1};THREE.Texture.prototype={clone:function(){return new THREE.Texture(this.image,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter)}};
93 94
THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;THREE.UnsignedIntType=14;THREE.FloatType=15;THREE.AlphaFormat=16;THREE.RGBFormat=17;
THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;
95 96 97 98
THREE.RenderTarget=function(a,b,d){this.width=a;this.height=b;d=d||{};this.wrapS=d.wrapS!==undefined?d.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=d.wrapT!==undefined?d.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=d.magFilter!==undefined?d.magFilter:THREE.LinearFilter;this.minFilter=d.minFilter!==undefined?d.minFilter:THREE.LinearMipMapLinearFilter;this.format=d.format!==undefined?d.format:THREE.RGBFormat;this.type=d.type!==undefined?d.type:THREE.UnsignedByteType};
var Uniforms={clone:function(a){var b,d,f,h={};for(b in a){h[b]={};for(d in a[b]){f=a[b][d];h[b][d]=f instanceof THREE.Color||f instanceof THREE.Vector3||f instanceof THREE.Texture?f.clone():f}}return h},merge:function(a){var b,d,f,h={};for(b=0;b<a.length;b++){f=this.clone(a[b]);for(d in f)h[d]=f[d]}return h}};THREE.Particle=function(a){THREE.Object3D.call(this);this.materials=a instanceof Array?a:[a];this.matrixAutoUpdate=!1};THREE.Particle.prototype=new THREE.Object3D;
THREE.Particle.prototype.constructor=THREE.Particle;THREE.ParticleSystem=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.sortParticles=!1};THREE.ParticleSystem.prototype=new THREE.Object3D;THREE.ParticleSystem.prototype.constructor=THREE.ParticleSystem;THREE.Line=function(a,b,d){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.type=d!=undefined?d:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;
THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b&&b.length?b:[b];this.flipSided=!1;this.doubleSided=!1;this.overdraw=!1;if(this.geometry){this.geometry.boundingSphere||this.geometry.computeBoundingSphere();this.boundRadius=a.boundingSphere.radius}};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.Mesh.prototype.supr=THREE.Object3D.prototype;
99
THREE.Bone=function(a){THREE.Object3D.call(this);this.skin=a;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;
100 101 102 103
THREE.Bone.prototype.update=function(a,b,d){this.matrixAutoUpdate&&(b|=this.updateMatrix());if(b||this.matrixWorldNeedsUpdate){a?this.skinMatrix.multiply(a,this.matrix):this.skinMatrix.copy(this.matrix);this.matrixWorldNeedsUpdate=!1;b=!0}var f,h=this.children.length;if(this.hasNoneBoneChildren){this.matrixWorld.multiply(this.skin.matrixWorld,this.skinMatrix);for(f=0;f<h;f++){a=this.children[f];a instanceof THREE.Bone?a.update(this.skinMatrix,b,d):a.update(this.matrixWorld,!0,d)}}else for(f=0;f<h;f++)this.children[f].update(this.skinMatrix,
b,d)};THREE.Bone.prototype.addChild=function(a){if(this.children.indexOf(a)===-1){a.parent!==undefined&&a.parent.removeChild(a);a.parent=this;this.children.push(a);if(!(a instanceof THREE.Bone))this.hasNoneBoneChildren=!0}};
THREE.Sound=function(a,b,d,f){THREE.Object3D.call(this);this.isLoaded=!1;this.isAddedToDOM=!1;this.isPlaying=!1;this.duration=-1;this.radius=b!==undefined?Math.abs(b):100;this.volume=Math.min(1,Math.max(0,d!==undefined?d:1));this.domElement=document.createElement("audio");this.domElement.volume=0;this.domElement.pan=0;this.domElement.loop=f!==undefined?f:!0;this.sources=a instanceof Array?a:[a];var h;d=this.sources.length;for(a=0;a<d;a++){b=this.sources[a];b.toLowerCase();if(b.indexOf(".mp3")!==-1)h=
"audio/mpeg";else if(b.indexOf(".ogg")!==-1)h="audio/ogg";else b.indexOf(".wav")!==-1&&(h="audio/wav");if(this.domElement.canPlayType(h)){h=document.createElement("source");h.src=this.sources[a];this.domElement.THREESound=this;this.domElement.appendChild(h);this.domElement.addEventListener("canplay",this.onLoad,!0);this.domElement.load();break}}};THREE.Sound.prototype=new THREE.Object3D;THREE.Sound.prototype.constructor=THREE.Sound;THREE.Sound.prototype.supr=THREE.Object3D.prototype;
104 105
THREE.Sound.prototype.onLoad=function(){var a=this.THREESound;if(!a.isLoaded){this.removeEventListener("canplay",this.onLoad,!0);a.isLoaded=!0;a.duration=this.duration;a.isPlaying&&a.play()}};THREE.Sound.prototype.addToDOM=function(a){this.isAddedToDOM=!0;a.appendChild(this.domElement)};THREE.Sound.prototype.play=function(a){this.isPlaying=!0;if(this.isLoaded){this.domElement.play();if(a)this.domElement.currentTime=a%this.duration}};THREE.Sound.prototype.pause=function(){this.isPlaying=!1;this.domElement.pause()};
THREE.Sound.prototype.stop=function(){this.isPlaying=!1;this.domElement.pause();this.domElement.currentTime=0};THREE.Sound.prototype.calculateVolumeAndPan=function(a){a=a.length();this.domElement.volume=a<=this.radius?this.volume*(1-a/this.radius):0};
106
THREE.Sound.prototype.update=function(a,b,d){if(this.matrixAutoUpdate){this.matrix.setPosition(this.position);b=!0}if(b||this.matrixWorldNeedsUpdate){a?this.matrixWorld.multiply(a,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=!1;b=!0}var f=this.children.length;for(a=0;a<f;a++)this.children[a].update(this.matrixWorld,b,d)};
107
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.fog=null;this.objects=[];this.lights=[];this.sounds=[];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.addChild=function(a){this.supr.addChild.call(this,a);this.addChildRecurse(a)};
108 109 110 111
THREE.Scene.prototype.addChildRecurse=function(a){if(a instanceof THREE.Light)this.lights.indexOf(a)===-1&&this.lights.push(a);else if(a instanceof THREE.Sound)this.sounds.indexOf(a)===-1&&this.sounds.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.objects.indexOf(a)===-1){this.objects.push(a);this.__objectsAdded.push(a)}for(var b=0;b<a.children.length;b++)this.addChildRecurse(a.children[b])};
THREE.Scene.prototype.removeChild=function(a){this.supr.removeChild.call(this,a);this.removeChildRecurse(a)};THREE.Scene.prototype.removeChildRecurse=function(a){if(a instanceof THREE.Light){var b=this.lights.indexOf(a);b!==-1&&this.lights.splice(b,1)}else if(a instanceof THREE.Sound){b=this.sounds.indexOf(a);b!==-1&&this.sounds.splice(b,1)}else if(!(a instanceof THREE.Camera)){b=this.objects.indexOf(a);if(b!==-1){this.objects.splice(b,1);this.__objectsRemoved.push(a)}}for(b=0;b<a.children.length;b++)this.removeChildRecurse(a.children[b])};
THREE.Scene.prototype.addObject=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeObject=THREE.Scene.prototype.removeChild;THREE.Scene.prototype.addLight=THREE.Scene.prototype.addChild;THREE.Scene.prototype.removeLight=THREE.Scene.prototype.removeChild;THREE.Fog=function(a,b,d){this.color=new THREE.Color(a);this.near=b||1;this.far=d||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
THREE.SoundRenderer=function(){this.volume=1;this.domElement=document.createElement("div");this.domElement.id="THREESound";this.cameraPosition=new THREE.Vector3;this.soundPosition=new THREE.Vector3;this.render=function(a,b,d){d&&a.update(undefined,!1,b);d=a.sounds;var f,h=d.length;for(f=0;f<h;f++){a=d[f];this.soundPosition.set(a.matrixWorld.n14,a.matrixWorld.n24,a.matrixWorld.n34);this.soundPosition.subSelf(b.position);if(a.isPlaying&&a.isLoaded){a.isAddedToDOM||a.addToDOM(this.domElement);a.calculateVolumeAndPan(this.soundPosition)}}}};
112 113 114 115 116
THREE.WebGLRenderer=function(a){function b(e,j,k){var g,i,u,o=e.vertices,r=o.length,x=e.colors,s=x.length,v=e.__vertexArray,J=e.__colorArray,P=e.__sortArray,N=e.__dirtyVertices,I=e.__dirtyColors;if(k.sortParticles){Ga.multiplySelf(k.matrixWorld);for(g=0;g<r;g++){i=o[g].position;Ba.copy(i);Ga.multiplyVector3(Ba);P[g]=[Ba.z,g]}P.sort(function(K,G){return G[0]-K[0]});for(g=0;g<r;g++){i=o[P[g][1]].position;u=g*3;v[u]=i.x;v[u+1]=i.y;v[u+2]=i.z}for(g=0;g<s;g++){u=g*3;color=x[P[g][1]];J[u]=color.r;J[u+1]=
color.g;J[u+2]=color.b}}else{if(N)for(g=0;g<r;g++){i=o[g].position;u=g*3;v[u]=i.x;v[u+1]=i.y;v[u+2]=i.z}if(I)for(g=0;g<s;g++){color=x[g];u=g*3;J[u]=color.r;J[u+1]=color.g;J[u+2]=color.b}}if(N||k.sortParticles){c.bindBuffer(c.ARRAY_BUFFER,e.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,v,j)}if(I||k.sortParticles){c.bindBuffer(c.ARRAY_BUFFER,e.__webGLColorBuffer);c.bufferData(c.ARRAY_BUFFER,J,j)}}function d(e,j){e.fragmentShader=j.fragmentShader;e.vertexShader=j.vertexShader;e.uniforms=Uniforms.clone(j.uniforms)}
function f(e,j,k,g,i){g.program||oa.initMaterial(g,j,k);var u=g.program,o=u.uniforms,r=g.uniforms;if(u!=na){c.useProgram(u);na=u;c.uniformMatrix4fv(o.projectionMatrix,!1,Pa)}if(k&&(g instanceof THREE.MeshBasicMaterial||g instanceof THREE.MeshLambertMaterial||g instanceof THREE.MeshPhongMaterial||g instanceof THREE.LineBasicMaterial||g instanceof THREE.ParticleBasicMaterial)){r.fogColor.value.setHex(k.color.hex);if(k instanceof THREE.Fog){r.fogNear.value=k.near;r.fogFar.value=k.far}else if(k instanceof
THREE.FogExp2)r.fogDensity.value=k.density}if(g instanceof THREE.MeshPhongMaterial||g instanceof THREE.MeshLambertMaterial){var x,s,v=0,J=0,P=0,N,I,K,G=oa.lights,ha=G.directional.colors,t=G.directional.positions,da=G.point.colors,ba=G.point.positions,ga=0,z=0;k=s=s=0;for(x=j.length;k<x;k++){s=j[k];N=s.color;I=s.position;K=s.intensity;if(s instanceof THREE.AmbientLight){v+=N.r;J+=N.g;P+=N.b}else if(s instanceof THREE.DirectionalLight){s=ga*3;ha[s]=N.r*K;ha[s+1]=N.g*K;ha[s+2]=N.b*K;t[s]=I.x;t[s+1]=
I.y;t[s+2]=I.z;ga+=1}else if(s instanceof THREE.PointLight){s=z*3;da[s]=N.r*K;da[s+1]=N.g*K;da[s+2]=N.b*K;ba[s]=I.x;ba[s+1]=I.y;ba[s+2]=I.z;z+=1}}for(k=ga*3;k<ha.length;k++)ha[k]=0;for(k=z*3;k<da.length;k++)da[k]=0;G.point.length=z;G.directional.length=ga;G.ambient[0]=v;G.ambient[1]=J;G.ambient[2]=P;j=oa.lights;r.enableLighting.value=j.directional.length+j.point.length;r.ambientLightColor.value=j.ambient;r.directionalLightColor.value=j.directional.colors;r.directionalLightDirection.value=j.directional.positions;
117
r.pointLightColor.value=j.point.colors;r.pointLightPosition.value=j.point.positions}if(g instanceof THREE.MeshBasicMaterial||g instanceof THREE.MeshLambertMaterial||g instanceof THREE.MeshPhongMaterial){r.diffuse.value.setRGB(g.color.r*g.opacity,g.color.g*g.opacity,g.color.b*g.opacity);r.opacity.value=g.opacity;r.map.texture=g.map;r.lightMap.texture=g.lightMap;r.envMap.texture=g.envMap;r.reflectivity.value=g.reflectivity;r.refractionRatio.value=g.refractionRatio;r.combine.value=g.combine;r.useRefract.value=
M
Mr.doob 已提交
118
g.envMap&&g.envMap.mapping instanceof THREE.CubeRefractionMapping}if(g instanceof THREE.LineBasicMaterial){r.diffuse.value.setRGB(g.color.r*g.opacity,g.color.g*g.opacity,g.color.b*g.opacity);r.opacity.value=g.opacity}else if(g instanceof THREE.ParticleBasicMaterial){r.psColor.value.setRGB(g.color.r*g.opacity,g.color.g*g.opacity,g.color.b*g.opacity);r.opacity.value=g.opacity;r.size.value=g.size;r.map.texture=g.map}else if(g instanceof THREE.MeshPhongMaterial){r.ambient.value.setRGB(g.ambient.r,g.ambient.g,
119 120 121 122 123
g.ambient.b);r.specular.value.setRGB(g.specular.r,g.specular.g,g.specular.b);r.shininess.value=g.shininess}else if(g instanceof THREE.MeshDepthMaterial){r.mNear.value=e.near;r.mFar.value=e.far;r.opacity.value=g.opacity}else if(g instanceof THREE.MeshNormalMaterial)r.opacity.value=g.opacity;for(var B in r)if(v=u.uniforms[B]){k=r[B];x=k.type;j=k.value;if(x=="i")c.uniform1i(v,j);else if(x=="f")c.uniform1f(v,j);else if(x=="fv1")c.uniform1fv(v,j);else if(x=="fv")c.uniform3fv(v,j);else if(x=="v2")c.uniform2f(v,
j.x,j.y);else if(x=="v3")c.uniform3f(v,j.x,j.y,j.z);else if(x=="c")c.uniform3f(v,j.r,j.g,j.b);else if(x=="t"){c.uniform1i(v,j);if(k=k.texture)if(k.image instanceof Array&&k.image.length==6){if(k.image.length==6){if(k.needsUpdate){if(k.__wasSetOnce){c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webGLTextureCube);for(x=0;x<6;++x)c.texSubImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+x,0,0,0,c.RGBA,c.UNSIGNED_BYTE,k.image[x])}else{k.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webGLTextureCube);
for(x=0;x<6;++x)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+x,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,k.image[x]);k.__wasSetOnce=!0}V(c.TEXTURE_CUBE_MAP,k,k.image[0]);c.bindTexture(c.TEXTURE_CUBE_MAP,null);k.needsUpdate=!1}c.activeTexture(c.TEXTURE0+j);c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webGLTextureCube)}}else{if(k.needsUpdate){if(k.__wasSetOnce){c.bindTexture(c.TEXTURE_2D,k.__webGLTexture);c.texSubImage2D(c.TEXTURE_2D,0,0,0,c.RGBA,c.UNSIGNED_BYTE,k.image)}else{k.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,
k.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,k.image);k.__wasSetOnce=!0}V(c.TEXTURE_2D,k,k.image);c.bindTexture(c.TEXTURE_2D,null);k.needsUpdate=!1}c.activeTexture(c.TEXTURE0+j);c.bindTexture(c.TEXTURE_2D,k.__webGLTexture)}}}c.uniformMatrix4fv(o.modelViewMatrix,!1,i._modelViewMatrixArray);c.uniformMatrix3fv(o.normalMatrix,!1,i._normalMatrixArray);(g instanceof THREE.MeshShaderMaterial||g instanceof THREE.MeshPhongMaterial||g.envMap)&&c.uniform3f(o.cameraPosition,e.position.x,
e.position.y,e.position.z);(g instanceof THREE.MeshShaderMaterial||g.envMap||g.skinning)&&c.uniformMatrix4fv(o.objectMatrix,!1,i._objectMatrixArray);(g instanceof THREE.MeshPhongMaterial||g instanceof THREE.MeshLambertMaterial||g instanceof THREE.MeshShaderMaterial||g.skinning)&&c.uniformMatrix4fv(o.viewMatrix,!1,Ja);if(g.skinning){c.uniformMatrix4fv(o.cameraInverseMatrix,!1,Ja);c.uniformMatrix4fv(o.boneGlobalMatrices,!1,i.boneMatrices)}return u}function h(e,j,k,g,i,u){e=f(e,j,k,g,u).attributes;c.bindBuffer(c.ARRAY_BUFFER,
124 125 126
i.__webGLVertexBuffer);c.vertexAttribPointer(e.position,3,c.FLOAT,!1,0,0);if(e.color>=0){c.bindBuffer(c.ARRAY_BUFFER,i.__webGLColorBuffer);c.vertexAttribPointer(e.color,3,c.FLOAT,!1,0,0)}if(e.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,i.__webGLNormalBuffer);c.vertexAttribPointer(e.normal,3,c.FLOAT,!1,0,0)}if(e.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,i.__webGLTangentBuffer);c.vertexAttribPointer(e.tangent,4,c.FLOAT,!1,0,0)}if(e.uv>=0)if(i.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,i.__webGLUVBuffer);
c.vertexAttribPointer(e.uv,2,c.FLOAT,!1,0,0);c.enableVertexAttribArray(e.uv)}else c.disableVertexAttribArray(e.uv);if(e.uv2>=0)if(i.__webGLUV2Buffer){c.bindBuffer(c.ARRAY_BUFFER,i.__webGLUV2Buffer);c.vertexAttribPointer(e.uv2,2,c.FLOAT,!1,0,0);c.enableVertexAttribArray(e.uv2)}else c.disableVertexAttribArray(e.uv2);if(g.skinning&&e.skinVertexA>=0&&e.skinVertexB>=0&&e.skinIndex>=0&&e.skinWeight>=0){c.bindBuffer(c.ARRAY_BUFFER,i.__webGLSkinVertexABuffer);c.vertexAttribPointer(e.skinVertexA,4,c.FLOAT,
!1,0,0);c.bindBuffer(c.ARRAY_BUFFER,i.__webGLSkinVertexBBuffer);c.vertexAttribPointer(e.skinVertexB,4,c.FLOAT,!1,0,0);c.bindBuffer(c.ARRAY_BUFFER,i.__webGLSkinIndicesBuffer);c.vertexAttribPointer(e.skinIndex,4,c.FLOAT,!1,0,0);c.bindBuffer(c.ARRAY_BUFFER,i.__webGLSkinWeightsBuffer);c.vertexAttribPointer(e.skinWeight,4,c.FLOAT,!1,0,0)}if(u instanceof THREE.Mesh)if(g.wireframe){c.lineWidth(g.wireframeLinewidth);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,i.__webGLLineBuffer);c.drawElements(c.LINES,i.__webGLLineCount,
M
Mr.doob 已提交
127
c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,i.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,i.__webGLFaceCount,c.UNSIGNED_SHORT,0)}else if(u instanceof THREE.Line){u=u.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(g.linewidth);c.drawArrays(u,0,i.__webGLLineCount)}else if(u instanceof THREE.ParticleSystem)c.drawArrays(c.POINTS,0,i.__webGLParticleCount);else u instanceof THREE.Ribbon&&c.drawArrays(c.TRIANGLE_STRIP,0,i.__webGLVertexCount)}function n(e,j){if(!e.__webGLVertexBuffer)e.__webGLVertexBuffer=
128
c.createBuffer();if(!e.__webGLNormalBuffer)e.__webGLNormalBuffer=c.createBuffer();if(e.hasPos){c.bindBuffer(c.ARRAY_BUFFER,e.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,e.positionArray,c.DYNAMIC_DRAW);c.enableVertexAttribArray(j.attributes.position);c.vertexAttribPointer(j.attributes.position,3,c.FLOAT,!1,0,0)}if(e.hasNormal){c.bindBuffer(c.ARRAY_BUFFER,e.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,e.normalArray,c.DYNAMIC_DRAW);c.enableVertexAttribArray(j.attributes.normal);c.vertexAttribPointer(j.attributes.normal,
M
Mr.doob 已提交
129
3,c.FLOAT,!1,0,0)}c.drawArrays(c.TRIANGLES,0,e.count);e.count=0}function l(e){if(pa!=e.doubleSided){e.doubleSided?c.disable(c.CULL_FACE):c.enable(c.CULL_FACE);pa=e.doubleSided}if(qa!=e.flipSided){e.flipSided?c.frontFace(c.CW):c.frontFace(c.CCW);qa=e.flipSided}}function q(e){if(Aa!=e){e?c.enable(c.DEPTH_TEST):c.disable(c.DEPTH_TEST);Aa=e}}function m(e){ra[0].set(e.n41-e.n11,e.n42-e.n12,e.n43-e.n13,e.n44-e.n14);ra[1].set(e.n41+e.n11,e.n42+e.n12,e.n43+e.n13,e.n44+e.n14);ra[2].set(e.n41+e.n21,e.n42+e.n22,
130 131 132
e.n43+e.n23,e.n44+e.n24);ra[3].set(e.n41-e.n21,e.n42-e.n22,e.n43-e.n23,e.n44-e.n24);ra[4].set(e.n41-e.n31,e.n42-e.n32,e.n43-e.n33,e.n44-e.n34);ra[5].set(e.n41+e.n31,e.n42+e.n32,e.n43+e.n33,e.n44+e.n34);var j;for(e=0;e<6;e++){j=ra[e];j.divideScalar(Math.sqrt(j.x*j.x+j.y*j.y+j.z*j.z))}}function w(e){for(var j=e.matrixWorld,k=-e.geometry.boundingSphere.radius*Math.max(e.scale.x,Math.max(e.scale.y,e.scale.z)),g=0;g<6;g++){e=ra[g].x*j.n14+ra[g].y*j.n24+ra[g].z*j.n34+ra[g].w;if(e<=k)return!1}return!0}function A(e,
j){e.list[e.count]=j;e.count+=1}function y(e){var j,k,g=e.object,i=e.opaque,u=e.transparent;u.count=0;e=i.count=0;for(j=g.materials.length;e<j;e++){k=g.materials[e];k.opacity&&k.opacity<1||k.blending!=THREE.NormalBlending?A(u,k):A(i,k)}}function D(e){var j,k,g,i,u=e.object,o=e.buffer,r=e.opaque,x=e.transparent;x.count=0;e=r.count=0;for(g=u.materials.length;e<g;e++){j=u.materials[e];if(j instanceof THREE.MeshFaceMaterial){j=0;for(k=o.materials.length;j<k;j++)(i=o.materials[j])&&(i.opacity&&i.opacity<
1||i.blending!=THREE.NormalBlending?A(x,i):A(r,i))}else{i=j;i.opacity&&i.opacity<1||i.blending!=THREE.NormalBlending?A(x,i):A(r,i)}}}function E(e,j){return j.z-e.z}function F(e,j){e._modelViewMatrix.multiplyToArray(j.matrixWorldInverse,e.matrixWorld,e._modelViewMatrixArray);THREE.Matrix4.makeInvert3x3(e._modelViewMatrix).transposeIntoArray(e._normalMatrixArray)}function H(e){function j(J){var P=[];k=0;for(g=J.length;k<g;k++)J[k]==undefined?P.push("undefined"):P.push(J[k].id);return P.join("_")}var k,
133
g,i,u,o,r,x,s,v={};e.geometryGroups={};i=0;for(u=e.faces.length;i<u;i++){o=e.faces[i];r=o.materials;x=j(r);v[x]==undefined&&(v[x]={hash:x,counter:0});s=v[x].hash+"_"+v[x].counter;e.geometryGroups[s]==undefined&&(e.geometryGroups[s]={faces:[],materials:r,vertices:0});o=o instanceof THREE.Face3?3:4;if(e.geometryGroups[s].vertices+o>65535){v[x].counter+=1;s=v[x].hash+"_"+v[x].counter;e.geometryGroups[s]==undefined&&(e.geometryGroups[s]={faces:[],materials:r,vertices:0})}e.geometryGroups[s].faces.push(i);
134 135
e.geometryGroups[s].vertices+=o}}function L(e,j,k){e.push({buffer:j,object:k,opaque:{list:[],count:0},transparent:{list:[],count:0}})}function M(e){if(e!=za){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;case THREE.BillboardBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.SRC_ALPHA,c.ONE_MINUS_SRC_ALPHA);break;case THREE.ReverseSubtractiveBlending:c.blendEquation(c.FUNC_REVERSE_SUBTRACT);
c.blendFunc(c.ONE,c.ONE);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}za=e}}function V(e,j,k){if((k.width&k.width-1)==0&&(k.height&k.height-1)==0){c.texParameteri(e,c.TEXTURE_WRAP_S,Y(j.wrapS));c.texParameteri(e,c.TEXTURE_WRAP_T,Y(j.wrapT));c.texParameteri(e,c.TEXTURE_MAG_FILTER,Y(j.magFilter));c.texParameteri(e,c.TEXTURE_MIN_FILTER,Y(j.minFilter));c.generateMipmap(e)}else{c.texParameteri(e,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(e,c.TEXTURE_WRAP_T,
A
alteredq 已提交
136
c.CLAMP_TO_EDGE);c.texParameteri(e,c.TEXTURE_MAG_FILTER,aa(j.magFilter));c.texParameteri(e,c.TEXTURE_MIN_FILTER,aa(j.minFilter))}}function X(e){if(e&&!e.__webGLFramebuffer){e.__webGLFramebuffer=c.createFramebuffer();e.__webGLRenderbuffer=c.createRenderbuffer();e.__webGLTexture=c.createTexture();c.bindRenderbuffer(c.RENDERBUFFER,e.__webGLRenderbuffer);c.renderbufferStorage(c.RENDERBUFFER,c.DEPTH_COMPONENT16,e.width,e.height);c.bindTexture(c.TEXTURE_2D,e.__webGLTexture);c.texParameteri(c.TEXTURE_2D,
137
c.TEXTURE_WRAP_S,Y(e.wrapS));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,Y(e.wrapT));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,Y(e.magFilter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,Y(e.minFilter));c.texImage2D(c.TEXTURE_2D,0,Y(e.format),e.width,e.height,0,Y(e.format),Y(e.type),null);c.bindFramebuffer(c.FRAMEBUFFER,e.__webGLFramebuffer);c.framebufferTexture2D(c.FRAMEBUFFER,c.COLOR_ATTACHMENT0,c.TEXTURE_2D,e.__webGLTexture,0);c.framebufferRenderbuffer(c.FRAMEBUFFER,c.DEPTH_ATTACHMENT,
A
alteredq 已提交
138 139 140 141 142 143 144 145 146 147
c.RENDERBUFFER,e.__webGLRenderbuffer);c.bindTexture(c.TEXTURE_2D,null);c.bindRenderbuffer(c.RENDERBUFFER,null);c.bindFramebuffer(c.FRAMEBUFFER,null)}var j,k;if(e){j=e.__webGLFramebuffer;k=e.width;e=e.height}else{j=null;k=Ea;e=Fa}if(j!=la){c.bindFramebuffer(c.FRAMEBUFFER,j);c.viewport(va,Da,k,e);la=j}}function ca(e,j){var k;if(e=="fragment")k=c.createShader(c.FRAGMENT_SHADER);else e=="vertex"&&(k=c.createShader(c.VERTEX_SHADER));c.shaderSource(k,j);c.compileShader(k);if(!c.getShaderParameter(k,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(k));
return null}return k}function aa(e){switch(e){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return c.NEAREST;case THREE.LinearFilter:case THREE.LinearMipMapNearestFilter:case THREE.LinearMipMapLinearFilter:return c.LINEAR}}function Y(e){switch(e){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;
case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR;case THREE.ByteType:return c.BYTE;case THREE.UnsignedByteType:return c.UNSIGNED_BYTE;case THREE.ShortType:return c.SHORT;case THREE.UnsignedShortType:return c.UNSIGNED_SHORT;case THREE.IntType:return c.INT;case THREE.UnsignedShortType:return c.UNSIGNED_INT;case THREE.FloatType:return c.FLOAT;
case THREE.AlphaFormat:return c.ALPHA;case THREE.RGBFormat:return c.RGB;case THREE.RGBAFormat:return c.RGBA;case THREE.LuminanceFormat:return c.LUMINANCE;case THREE.LuminanceAlphaFormat:return c.LUMINANCE_ALPHA}return 0}var fa=document.createElement("canvas"),c,na=null,la=null,oa=this,pa=null,qa=null,za=null,Aa=null,va=0,Da=0,Ea=0,Fa=0,ra=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],Ga=new THREE.Matrix4,Pa=new Float32Array(16),Ja=new Float32Array(16),
Ba=new THREE.Vector4,Qa=!0,Ra=new THREE.Color(0),Sa=0;if(a){if(a.antialias!==undefined)Qa=a.antialias;a.clearColor!==undefined&&Ra.setHex(a.clearColor);if(a.clearAlpha!==undefined)Sa=a.clearAlpha}this.domElement=fa;this.autoClear=!0;this.sortObjects=!0;(function(e,j,k){try{if(!(c=fa.getContext("experimental-webgl",{antialias:e})))throw"Error creating WebGL context.";}catch(g){console.error(g)}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);
c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(j.r,j.g,j.b,k);_cullEnabled=!0})(Qa,Ra,Sa);this.context=c;this.lights={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[]}};this.setSize=function(e,j){fa.width=e;fa.height=j;this.setViewport(0,0,fa.width,fa.height)};this.setViewport=function(e,j,k,g){va=e;Da=j;Ea=k;Fa=g;c.viewport(va,Da,Ea,Fa)};this.setScissor=function(e,j,k,g){c.scissor(e,j,k,g)};this.enableScissorTest=
function(e){e?c.enable(c.SCISSOR_TEST):c.disable(c.SCISSOR_TEST)};this.setClearColorHex=function(e,j){var k=new THREE.Color(e);c.clearColor(k.r,k.g,k.b,j)};this.setClearColor=function(e,j){c.clearColor(e.r,e.g,e.b,j)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.initMaterial=function(e,j,k){var g,i;if(e instanceof THREE.MeshDepthMaterial)d(e,THREE.ShaderLib.depth);else if(e instanceof THREE.MeshNormalMaterial)d(e,THREE.ShaderLib.normal);else if(e instanceof THREE.MeshBasicMaterial)d(e,
THREE.ShaderLib.basic);else if(e instanceof THREE.MeshLambertMaterial)d(e,THREE.ShaderLib.lambert);else if(e instanceof THREE.MeshPhongMaterial)d(e,THREE.ShaderLib.phong);else if(e instanceof THREE.LineBasicMaterial)d(e,THREE.ShaderLib.basic);else e instanceof THREE.ParticleBasicMaterial&&d(e,THREE.ShaderLib.particle_basic);var u,o,r,x;i=r=x=0;for(u=j.length;i<u;i++){o=j[i];o instanceof THREE.DirectionalLight&&r++;o instanceof THREE.PointLight&&x++}if(x+r<=4)j=r;else{j=Math.ceil(4*r/(x+r));x=4-j}i=
{directional:j,point:x};x=e.fragmentShader;j=e.vertexShader;u={fog:k,map:e.map,envMap:e.envMap,lightMap:e.lightMap,vertexColors:e.vertexColors,skinning:e.skinning,maxDirLights:i.directional,maxPointLights:i.point};k=c.createProgram();i=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+u.maxDirLights,"#define MAX_POINT_LIGHTS "+u.maxPointLights,u.fog?"#define USE_FOG":"",u.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",u.map?"#define USE_MAP":"",u.envMap?"#define USE_ENVMAP":
"",u.lightMap?"#define USE_LIGHTMAP":"",u.vertexColors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");u=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+u.maxDirLights,"#define MAX_POINT_LIGHTS "+u.maxPointLights,u.map?"#define USE_MAP":"",u.envMap?"#define USE_ENVMAP":"",u.lightMap?"#define USE_LIGHTMAP":"",u.vertexColors?"#define USE_COLOR":"",u.skinning?"#define USE_SKINNING":"","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 vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n"].join("\n");
148 149
c.attachShader(k,ca("fragment",i+x));c.attachShader(k,ca("vertex",u+j));c.linkProgram(k);c.getProgramParameter(k,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(k,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");k.uniforms={};k.attributes={};e.program=k;k=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","cameraInverseMatrix","boneGlobalMatrices"];for(g in e.uniforms)k.push(g);g=e.program;x=0;for(j=k.length;x<
j;x++){i=k[x];g.uniforms[i]=c.getUniformLocation(g,i)}g=e.program;k=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];x=0;for(j=k.length;x<j;x++){i=k[x];g.attributes[i]=c.getAttribLocation(g,i)}g=e.program.attributes;c.enableVertexAttribArray(g.position);g.color>=0&&c.enableVertexAttribArray(g.color);g.normal>=0&&c.enableVertexAttribArray(g.normal);g.tangent>=0&&c.enableVertexAttribArray(g.tangent);if(e.skinning&&g.skinVertexA>=0&&g.skinVertexB>=
A
alteredq 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
0&&g.skinIndex>=0&&g.skinWeight>=0){c.enableVertexAttribArray(g.skinVertexA);c.enableVertexAttribArray(g.skinVertexB);c.enableVertexAttribArray(g.skinIndex);c.enableVertexAttribArray(g.skinWeight)}};this.render=function(e,j,k,g){var i,u,o,r,x,s,v,J,P=e.lights,N=e.fog;j.matrixAutoUpdate&&j.update();j.matrixWorldInverse.flattenToArray(Ja);j.projectionMatrix.flattenToArray(Pa);Ga.multiply(j.projectionMatrix,j.matrixWorldInverse);m(Ga);e.update(undefined,!1,j);this.initWebGLObjects(e,j);X(k);(this.autoClear||
g)&&this.clear();x=e.__webglObjects.length;for(g=0;g<x;g++){i=e.__webglObjects[g];v=i.object;if(v.visible)if(!(v instanceof THREE.Mesh)||w(v)){v.matrixWorld.flattenToArray(v._objectMatrixArray);F(v,j);D(i);i.render=!0;if(this.sortObjects){Ba.copy(v.position);Ga.multiplyVector3(Ba);i.z=Ba.z}}else i.render=!1;else i.render=!1}this.sortObjects&&e.__webglObjects.sort(E);s=e.__webglObjectsImmediate.length;for(g=0;g<s;g++){i=e.__webglObjectsImmediate[g];v=i.object;if(v.visible){v.matrixAutoUpdate&&v.matrixWorld.flattenToArray(v._objectMatrixArray);
F(v,j);y(i)}}M(THREE.NormalBlending);for(g=0;g<x;g++){i=e.__webglObjects[g];if(i.render){v=i.object;J=i.buffer;o=i.opaque;l(v);for(i=0;i<o.count;i++){r=o.list[i];q(r.depthTest);h(j,P,N,r,J,v)}}}for(g=0;g<s;g++){i=e.__webglObjectsImmediate[g];v=i.object;if(v.visible){o=i.opaque;l(v);for(i=0;i<o.count;i++){r=o.list[i];q(r.depthTest);u=f(j,P,N,r,v);v.render(function(I){n(I,u)})}}}for(g=0;g<x;g++){i=e.__webglObjects[g];if(i.render){v=i.object;J=i.buffer;o=i.transparent;l(v);for(i=0;i<o.count;i++){r=o.list[i];
M(r.blending);q(r.depthTest);h(j,P,N,r,J,v)}}}for(g=0;g<s;g++){i=e.__webglObjectsImmediate[g];v=i.object;if(v.visible){o=i.transparent;l(v);for(i=0;i<o.count;i++){r=o.list[i];M(r.blending);q(r.depthTest);u=f(j,P,N,r,v);v.render(function(I){n(I,u)})}}}if(k&&k.minFilter!==THREE.NearestFilter&&k.minFilter!==THREE.LinearFilter){c.bindTexture(c.TEXTURE_2D,k.__webGLTexture);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}};this.initWebGLObjects=function(e){if(!e.__webglObjects){e.__webglObjects=
[];e.__webglObjectsImmediate=[]}for(;e.__objectsAdded.length;){var j=e.__objectsAdded[0],k=e,g=void 0,i=void 0,u=void 0;if(j._modelViewMatrix==undefined){j._modelViewMatrix=new THREE.Matrix4;j._normalMatrixArray=new Float32Array(9);j._modelViewMatrixArray=new Float32Array(16);j._objectMatrixArray=new Float32Array(16);j.matrixWorld.flattenToArray(j._objectMatrixArray)}if(j instanceof THREE.Mesh){i=j.geometry;i.geometryGroups==undefined&&H(i);for(g in i.geometryGroups){u=i.geometryGroups[g];if(!u.__webGLVertexBuffer){var o=
u;o.__webGLVertexBuffer=c.createBuffer();o.__webGLNormalBuffer=c.createBuffer();o.__webGLTangentBuffer=c.createBuffer();o.__webGLColorBuffer=c.createBuffer();o.__webGLUVBuffer=c.createBuffer();o.__webGLUV2Buffer=c.createBuffer();o.__webGLSkinVertexABuffer=c.createBuffer();o.__webGLSkinVertexBBuffer=c.createBuffer();o.__webGLSkinIndicesBuffer=c.createBuffer();o.__webGLSkinWeightsBuffer=c.createBuffer();o.__webGLFaceBuffer=c.createBuffer();o.__webGLLineBuffer=c.createBuffer();o=u;var r=j,x=void 0,s=
void 0,v=0,J=0,P=0,N=r.geometry.faces,I=o.faces;x=0;for(s=I.length;x<s;x++){fi=I[x];face=N[fi];if(face instanceof THREE.Face3){v+=3;J+=1;P+=3}else if(face instanceof THREE.Face4){v+=4;J+=2;P+=4}}o.__vertexArray=new Float32Array(v*3);o.__normalArray=new Float32Array(v*3);o.__tangentArray=new Float32Array(v*4);o.__colorArray=new Float32Array(v*3);o.__uvArray=new Float32Array(v*2);o.__uv2Array=new Float32Array(v*2);o.__skinVertexAArray=new Float32Array(v*4);o.__skinVertexBArray=new Float32Array(v*4);
o.__skinIndexArray=new Float32Array(v*4);o.__skinWeightArray=new Float32Array(v*4);o.__faceArray=new Uint16Array(J*3);o.__lineArray=new Uint16Array(P*2);s=x=o;v=void 0;N=void 0;var K=void 0,G=void 0;K=void 0;I=!1;v=0;for(N=r.materials.length;v<N;v++){K=r.materials[v];if(K instanceof THREE.MeshFaceMaterial){K=0;for(G=s.materials.length;K<G;K++)if(s.materials[K]&&s.materials[K].shading!=undefined&&s.materials[K].shading==THREE.SmoothShading){I=!0;break}}else if(K&&K.shading!=undefined&&K.shading==THREE.SmoothShading){I=
!0;break}if(I)break}x.__needsSmoothNormals=I;o.__webGLFaceCount=J*3;o.__webGLLineCount=P*2;i.__dirtyVertices=!0;i.__dirtyElements=!0;i.__dirtyUvs=!0;i.__dirtyNormals=!0;i.__dirtyTangents=!0;i.__dirtyColors=!0}L(k.__webglObjects,u,j)}}else if(j instanceof THREE.Ribbon){i=j.geometry;if(!i.__webGLVertexBuffer){g=i;g.__webGLVertexBuffer=c.createBuffer();g.__webGLColorBuffer=c.createBuffer();g=i;u=g.vertices.length;g.__vertexArray=new Float32Array(u*3);g.__colorArray=new Float32Array(u*3);g.__webGLVertexCount=
u;i.__dirtyVertices=!0;i.__dirtyColors=!0}L(k.__webglObjects,i,j)}else if(j instanceof THREE.Line){i=j.geometry;if(!i.__webGLVertexBuffer){g=i;g.__webGLVertexBuffer=c.createBuffer();g.__webGLColorBuffer=c.createBuffer();g=i;u=g.vertices.length;g.__vertexArray=new Float32Array(u*3);g.__colorArray=new Float32Array(u*3);g.__webGLLineCount=u;i.__dirtyVertices=!0;i.__dirtyColors=!0}L(k.__webglObjects,i,j)}else if(j instanceof THREE.ParticleSystem){i=j.geometry;if(!i.__webGLVertexBuffer){g=i;g.__webGLVertexBuffer=
c.createBuffer();g.__webGLColorBuffer=c.createBuffer();g=i;u=g.vertices.length;g.__vertexArray=new Float32Array(u*3);g.__colorArray=new Float32Array(u*3);g.__sortArray=[];g.__webGLParticleCount=u;i.__dirtyVertices=!0;i.__dirtyColors=!0}L(k.__webglObjects,i,j)}else THREE.MarchingCubes!==undefined&&j instanceof THREE.MarchingCubes&&k.__webglObjectsImmediate.push({object:j,opaque:{list:[],count:0},transparent:{list:[],count:0}});e.__objectsAdded.splice(0,1)}for(;e.__objectsRemoved.length;){j=e.__objectsRemoved[0];
k=e;i=void 0;g=void 0;for(i=k.__webglObjects.length-1;i>=0;i--){g=k.__webglObjects[i].object;j==g&&k.__webglObjects.splice(i,1)}e.__objectsRemoved.splice(0,1)}j=0;for(k=e.__webglObjects.length;j<k;j++){g=e.__webglObjects[j].object;u=void 0;i=void 0;o=void 0;if(g instanceof THREE.Mesh){i=g.geometry;for(u in i.geometryGroups){o=i.geometryGroups[u];if(i.__dirtyVertices||i.__dirtyElements||i.__dirtyUvs||i.__dirtyNormals||i.__dirtyColors||i.__dirtyTangents){J=c.DYNAMIC_DRAW;P=void 0;x=void 0;var ha=void 0,
t=void 0,da=void 0,ba=void 0,ga=void 0;ha=void 0;var z=void 0,B=void 0,C=void 0,O=void 0;z=void 0;B=void 0;C=void 0;t=void 0;z=void 0;B=void 0;C=void 0;O=void 0;z=void 0;B=void 0;C=void 0;O=void 0;z=void 0;B=void 0;C=void 0;O=void 0;z=void 0;B=void 0;C=void 0;O=void 0;z=void 0;B=void 0;C=void 0;O=void 0;t=void 0;ba=void 0;da=void 0;ga=void 0;var ia=G=K=I=N=v=r=s=0,W=0,p=0,Z=o.__vertexArray,Ha=o.__uvArray,Ia=o.__uv2Array,ma=o.__normalArray,Q=o.__tangentArray,$=o.__colorArray,R=o.__skinVertexAArray,
S=o.__skinVertexBArray,T=o.__skinIndexArray,U=o.__skinWeightArray,sa=o.__faceArray,ja=o.__lineArray,Ta=o.__needsSmoothNormals,ea=g.geometry,Ka=ea.__dirtyVertices,La=ea.__dirtyElements,Ca=ea.__dirtyUvs,Ma=ea.__dirtyNormals,Na=ea.__dirtyTangents,Oa=ea.__dirtyColors,ka=ea.vertices,Ua=o.faces,Va=ea.faces,Wa=ea.uvs,Xa=ea.uvs2,ta=ea.colors,wa=ea.skinVerticesA,xa=ea.skinVerticesB,ya=ea.skinIndices,ua=ea.skinWeights;P=0;for(x=Ua.length;P<x;P++){ha=Ua[P];t=Va[ha];ga=Wa[ha];ha=Xa[ha];da=t.vertexNormals;ba=
t.normal;if(t instanceof THREE.Face3){if(Ka){z=ka[t.a].position;B=ka[t.b].position;C=ka[t.c].position;Z[r]=z.x;Z[r+1]=z.y;Z[r+2]=z.z;Z[r+3]=B.x;Z[r+4]=B.y;Z[r+5]=B.z;Z[r+6]=C.x;Z[r+7]=C.y;Z[r+8]=C.z;r+=9}if(ua.length){z=ua[t.a];B=ua[t.b];C=ua[t.c];U[p]=z.x;U[p+1]=z.y;U[p+2]=z.z;U[p+3]=z.w;U[p+4]=B.x;U[p+5]=B.y;U[p+6]=B.z;U[p+7]=B.w;U[p+8]=C.x;U[p+9]=C.y;U[p+10]=C.z;U[p+11]=C.w;z=ya[t.a];B=ya[t.b];C=ya[t.c];T[p]=z.x;T[p+1]=z.y;T[p+2]=z.z;T[p+3]=z.w;T[p+4]=B.x;T[p+5]=B.y;T[p+6]=B.z;T[p+7]=B.w;T[p+8]=
C.x;T[p+9]=C.y;T[p+10]=C.z;T[p+11]=C.w;z=wa[t.a];B=wa[t.b];C=wa[t.c];R[p]=z.x;R[p+1]=z.y;R[p+2]=z.z;R[p+3]=1;R[p+4]=B.x;R[p+5]=B.y;R[p+6]=B.z;R[p+7]=1;R[p+8]=C.x;R[p+9]=C.y;R[p+10]=C.z;R[p+11]=1;z=xa[t.a];B=xa[t.b];C=xa[t.c];S[p]=z.x;S[p+1]=z.y;S[p+2]=z.z;S[p+3]=1;S[p+4]=B.x;S[p+5]=B.y;S[p+6]=B.z;S[p+7]=1;S[p+8]=C.x;S[p+9]=C.y;S[p+10]=C.z;S[p+11]=1;p+=12}if(Oa&&ta.length){z=ta[t.a];B=ta[t.b];C=ta[t.c];$[W]=z.r;$[W+1]=z.g;$[W+2]=z.b;$[W+3]=B.r;$[W+4]=B.g;$[W+5]=B.b;$[W+6]=C.r;$[W+7]=C.g;$[W+8]=C.b;
W+=9}if(Na&&ea.hasTangents){z=ka[t.a].tangent;B=ka[t.b].tangent;C=ka[t.c].tangent;Q[G]=z.x;Q[G+1]=z.y;Q[G+2]=z.z;Q[G+3]=z.w;Q[G+4]=B.x;Q[G+5]=B.y;Q[G+6]=B.z;Q[G+7]=B.w;Q[G+8]=C.x;Q[G+9]=C.y;Q[G+10]=C.z;Q[G+11]=C.w;G+=12}if(Ma)if(da.length==3&&Ta)for(t=0;t<3;t++){ba=da[t];ma[K]=ba.x;ma[K+1]=ba.y;ma[K+2]=ba.z;K+=3}else for(t=0;t<3;t++){ma[K]=ba.x;ma[K+1]=ba.y;ma[K+2]=ba.z;K+=3}if(Ca&&ga)for(t=0;t<3;t++){da=ga[t];Ha[v]=da.u;Ha[v+1]=da.v;v+=2}if(Ca&&ha)for(t=0;t<3;t++){ga=ha[t];Ia[N]=ga.u;Ia[N+1]=ga.v;
N+=2}if(La){sa[I]=s;sa[I+1]=s+1;sa[I+2]=s+2;I+=3;ja[ia]=s;ja[ia+1]=s+1;ja[ia+2]=s;ja[ia+3]=s+2;ja[ia+4]=s+1;ja[ia+5]=s+2;ia+=6;s+=3}}else if(t instanceof THREE.Face4){if(Ka){z=ka[t.a].position;B=ka[t.b].position;C=ka[t.c].position;O=ka[t.d].position;Z[r]=z.x;Z[r+1]=z.y;Z[r+2]=z.z;Z[r+3]=B.x;Z[r+4]=B.y;Z[r+5]=B.z;Z[r+6]=C.x;Z[r+7]=C.y;Z[r+8]=C.z;Z[r+9]=O.x;Z[r+10]=O.y;Z[r+11]=O.z;r+=12}if(ua.length){z=ua[t.a];B=ua[t.b];C=ua[t.c];O=ua[t.d];U[p]=z.x;U[p+1]=z.y;U[p+2]=z.z;U[p+3]=z.w;U[p+4]=B.x;U[p+5]=
B.y;U[p+6]=B.z;U[p+7]=B.w;U[p+8]=C.x;U[p+9]=C.y;U[p+10]=C.z;U[p+11]=C.w;U[p+12]=O.x;U[p+13]=O.y;U[p+14]=O.z;U[p+15]=O.w;z=ya[t.a];B=ya[t.b];C=ya[t.c];O=ya[t.d];T[p]=z.x;T[p+1]=z.y;T[p+2]=z.z;T[p+3]=z.w;T[p+4]=B.x;T[p+5]=B.y;T[p+6]=B.z;T[p+7]=B.w;T[p+8]=C.x;T[p+9]=C.y;T[p+10]=C.z;T[p+11]=C.w;T[p+12]=O.x;T[p+13]=O.y;T[p+14]=O.z;T[p+15]=O.w;z=wa[t.a];B=wa[t.b];C=wa[t.c];O=wa[t.d];R[p]=z.x;R[p+1]=z.y;R[p+2]=z.z;R[p+3]=1;R[p+4]=B.x;R[p+5]=B.y;R[p+6]=B.z;R[p+7]=1;R[p+8]=C.x;R[p+9]=C.y;R[p+10]=C.z;R[p+11]=
1;R[p+12]=O.x;R[p+13]=O.y;R[p+14]=O.z;R[p+15]=1;z=xa[t.a];B=xa[t.b];C=xa[t.c];O=xa[t.d];S[p]=z.x;S[p+1]=z.y;S[p+2]=z.z;S[p+3]=1;S[p+4]=B.x;S[p+5]=B.y;S[p+6]=B.z;S[p+7]=1;S[p+8]=C.x;S[p+9]=C.y;S[p+10]=C.z;S[p+11]=1;S[p+12]=O.x;S[p+13]=O.y;S[p+14]=O.z;S[p+15]=1;p+=16}if(Oa&&ta.length){z=ta[t.a];B=ta[t.b];C=ta[t.c];O=ta[t.d];$[W]=z.r;$[W+1]=z.g;$[W+2]=z.b;$[W+3]=B.r;$[W+4]=B.g;$[W+5]=B.b;$[W+6]=C.r;$[W+7]=C.g;$[W+8]=C.b;$[W+9]=O.r;$[W+10]=O.g;$[W+11]=O.b;W+=12}if(Na&&ea.hasTangents){z=ka[t.a].tangent;
B=ka[t.b].tangent;C=ka[t.c].tangent;t=ka[t.d].tangent;Q[G]=z.x;Q[G+1]=z.y;Q[G+2]=z.z;Q[G+3]=z.w;Q[G+4]=B.x;Q[G+5]=B.y;Q[G+6]=B.z;Q[G+7]=B.w;Q[G+8]=C.x;Q[G+9]=C.y;Q[G+10]=C.z;Q[G+11]=C.w;Q[G+12]=t.x;Q[G+13]=t.y;Q[G+14]=t.z;Q[G+15]=t.w;G+=16}if(Ma)if(da.length==4&&Ta)for(t=0;t<4;t++){ba=da[t];ma[K]=ba.x;ma[K+1]=ba.y;ma[K+2]=ba.z;K+=3}else for(t=0;t<4;t++){ma[K]=ba.x;ma[K+1]=ba.y;ma[K+2]=ba.z;K+=3}if(Ca&&ga)for(t=0;t<4;t++){da=ga[t];Ha[v]=da.u;Ha[v+1]=da.v;v+=2}if(Ca&&ha)for(t=0;t<4;t++){ga=ha[t];Ia[N]=
ga.u;Ia[N+1]=ga.v;N+=2}if(La){sa[I]=s;sa[I+1]=s+1;sa[I+2]=s+2;sa[I+3]=s;sa[I+4]=s+2;sa[I+5]=s+3;I+=6;ja[ia]=s;ja[ia+1]=s+1;ja[ia+2]=s;ja[ia+3]=s+3;ja[ia+4]=s+1;ja[ia+5]=s+2;ja[ia+6]=s+2;ja[ia+7]=s+3;ia+=8;s+=4}}}if(Ka){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,Z,J)}if(Oa&&ta.length){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLColorBuffer);c.bufferData(c.ARRAY_BUFFER,$,J)}if(Ma){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,ma,J)}if(Na&&
ea.hasTangents){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,Q,J)}if(Ca&&v>0){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,Ha,J)}if(Ca&&N>0){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLUV2Buffer);c.bufferData(c.ARRAY_BUFFER,Ia,J)}if(La){c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,o.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,sa,J);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,o.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,ja,J)}if(p>0){c.bindBuffer(c.ARRAY_BUFFER,
o.__webGLSkinVertexABuffer);c.bufferData(c.ARRAY_BUFFER,R,J);c.bindBuffer(c.ARRAY_BUFFER,o.__webGLSkinVertexBBuffer);c.bufferData(c.ARRAY_BUFFER,S,J);c.bindBuffer(c.ARRAY_BUFFER,o.__webGLSkinIndicesBuffer);c.bufferData(c.ARRAY_BUFFER,T,J);c.bindBuffer(c.ARRAY_BUFFER,o.__webGLSkinWeightsBuffer);c.bufferData(c.ARRAY_BUFFER,U,J)}}}i.__dirtyVertices=!1;i.__dirtyElements=!1;i.__dirtyUvs=!1;i.__dirtyNormals=!1;i.__dirtyTangents=!1;i.__dirtyColors=!1}else if(g instanceof THREE.Ribbon){i=g.geometry;if(i.__dirtyVertices||
i.__dirtyColors){g=i;u=c.DYNAMIC_DRAW;s=void 0;s=void 0;r=void 0;o=void 0;v=g.vertices;J=g.colors;N=v.length;P=J.length;I=g.__vertexArray;x=g.__colorArray;K=g.__dirtyColors;if(g.__dirtyVertices){for(s=0;s<N;s++){r=v[s].position;o=s*3;I[o]=r.x;I[o+1]=r.y;I[o+2]=r.z}c.bindBuffer(c.ARRAY_BUFFER,g.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,I,u)}if(K){for(s=0;s<P;s++){color=J[s];o=s*3;x[o]=color.r;x[o+1]=color.g;x[o+2]=color.b}c.bindBuffer(c.ARRAY_BUFFER,g.__webGLColorBuffer);c.bufferData(c.ARRAY_BUFFER,
x,u)}}i.__dirtyVertices=!1;i.__dirtyColors=!1}else if(g instanceof THREE.Line){i=g.geometry;if(i.__dirtyVertices||i.__dirtyColors){g=i;u=c.DYNAMIC_DRAW;s=void 0;s=void 0;r=void 0;o=void 0;v=g.vertices;J=g.colors;N=v.length;P=J.length;I=g.__vertexArray;x=g.__colorArray;K=g.__dirtyColors;if(g.__dirtyVertices){for(s=0;s<N;s++){r=v[s].position;o=s*3;I[o]=r.x;I[o+1]=r.y;I[o+2]=r.z}c.bindBuffer(c.ARRAY_BUFFER,g.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,I,u)}if(K){for(s=0;s<P;s++){color=J[s];o=s*
3;x[o]=color.r;x[o+1]=color.g;x[o+2]=color.b}c.bindBuffer(c.ARRAY_BUFFER,g.__webGLColorBuffer);c.bufferData(c.ARRAY_BUFFER,x,u)}}i.__dirtyVertices=!1;i.__dirtyColors=!1}else if(g instanceof THREE.ParticleSystem){i=g.geometry;(i.__dirtyVertices||i.__dirtyColors||g.sortParticles)&&b(i,c.DYNAMIC_DRAW,g);i.__dirtyVertices=!1;i.__dirtyColors=!1}}};this.setFaceCulling=function(e,j){if(e){!j||j=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);else e=="front"?c.cullFace(c.FRONT):
c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
M
Mr.doob 已提交
178 179 180 181
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 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_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",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 ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
M
Mr.doob 已提交
182 183 184
lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mColor = vec4( diffuse, opacity );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse  = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse  += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse  = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse  += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif\ngl_FragColor = gl_FragColor * totalLight;",
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[20];\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#else\ngl_Position = projectionMatrix * mvPosition;\n#endif"};
185
THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},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},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",
M
Mr.doob 已提交
186
value:1},ambientLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]}},particle:{psColor:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},size:{type:"f",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)}}};
187 188 189 190 191
THREE.ShaderLib={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3},opacity:{type:"f",value:1}},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}",vertexShader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{opacity:{type:"f",
value:1}},fragmentShader:"uniform float opacity;\nvarying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n}",vertexShader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"},basic:{uniforms:THREE.UniformsLib.common,fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;",THREE.Snippets.color_pars_fragment,
THREE.Snippets.map_pars_fragment,THREE.Snippets.lightmap_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );",THREE.Snippets.map_fragment,THREE.Snippets.lightmap_fragment,THREE.Snippets.color_fragment,THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertexShader:[THREE.Snippets.map_pars_vertex,THREE.Snippets.lightmap_pars_vertex,THREE.Snippets.envmap_pars_vertex,THREE.Snippets.color_pars_vertex,
THREE.Snippets.skinning_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.lightmap_vertex,THREE.Snippets.envmap_vertex,THREE.Snippets.color_vertex,THREE.Snippets.skinning_vertex,"}"].join("\n")},lambert:{uniforms:Uniforms.merge([THREE.UniformsLib.common,THREE.UniformsLib.lights]),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;\nvarying vec3 vLightWeighting;",THREE.Snippets.color_pars_fragment,THREE.Snippets.map_pars_fragment,
THREE.Snippets.lightmap_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );\ngl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );",THREE.Snippets.map_fragment,THREE.Snippets.lightmap_fragment,THREE.Snippets.color_fragment,THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertexShader:["varying vec3 vLightWeighting;",THREE.Snippets.map_pars_vertex,THREE.Snippets.lightmap_pars_vertex,
M
Mr.doob 已提交
192
THREE.Snippets.envmap_pars_vertex,THREE.Snippets.lights_pars_vertex,THREE.Snippets.color_pars_vertex,THREE.Snippets.skinning_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.lightmap_vertex,THREE.Snippets.envmap_vertex,THREE.Snippets.color_vertex,"vec3 transformedNormal = normalize( normalMatrix * normal );",THREE.Snippets.lights_vertex,THREE.Snippets.skinning_vertex,"}"].join("\n")},phong:{uniforms:Uniforms.merge([THREE.UniformsLib.common,
193 194
THREE.UniformsLib.lights,{ambient:{type:"c",value:new THREE.Color(328965)},specular:{type:"c",value:new THREE.Color(1118481)},shininess:{type:"f",value:30}}]),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;\nuniform vec3 ambient;\nuniform vec3 specular;\nuniform float shininess;\nvarying vec3 vLightWeighting;",THREE.Snippets.color_pars_fragment,THREE.Snippets.map_pars_fragment,THREE.Snippets.lightmap_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,
THREE.Snippets.lights_pars_fragment,"void main() {\ngl_FragColor = vec4( vLightWeighting, 1.0 );",THREE.Snippets.lights_fragment,THREE.Snippets.map_fragment,THREE.Snippets.lightmap_fragment,THREE.Snippets.color_fragment,THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertexShader:["#define PHONG\nvarying vec3 vLightWeighting;\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.Snippets.map_pars_vertex,THREE.Snippets.lightmap_pars_vertex,THREE.Snippets.envmap_pars_vertex,
M
Mr.doob 已提交
195
THREE.Snippets.lights_pars_vertex,THREE.Snippets.color_pars_vertex,THREE.Snippets.skinning_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.lightmap_vertex,THREE.Snippets.envmap_vertex,THREE.Snippets.color_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 transformedNormal = normalize( normalMatrix * normal );\nvNormal = transformedNormal;",
196
THREE.Snippets.lights_vertex,THREE.Snippets.skinning_vertex,"}"].join("\n")},particle_basic:{uniforms:THREE.UniformsLib.particle,fragmentShader:["uniform vec3 psColor;\nuniform float opacity;",THREE.Snippets.color_pars_fragment,THREE.Snippets.map_particle_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( psColor, opacity );",THREE.Snippets.map_particle_fragment,THREE.Snippets.color_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertexShader:["uniform float size;",
M
Mr.doob 已提交
197
THREE.Snippets.color_pars_vertex,"void main() {",THREE.Snippets.color_vertex,"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\ngl_Position = projectionMatrix * mvPosition;\ngl_PointSize = size;\n}"].join("\n")}};