Three.js 276.0 KB
Newer Older
M
Mr.doob 已提交
1
// Three.js r42 - http://github.com/mrdoob/three.js
2
var THREE=THREE||{};if(!window.Int32Array)window.Int32Array=Array,window.Float32Array=Array;THREE.Color=function(b){this.setHex(b)};
M
Mr.doob 已提交
3
THREE.Color.prototype={copy:function(b){this.r=b.r;this.g=b.g;this.b=b.b;this.hex=b.hex},setHex:function(b){this.hex=~~b&16777215;this.updateRGB()},setRGB:function(b,c,e){this.r=b;this.g=c;this.b=e;this.updateHex()},setHSV:function(b,c,e){var f,g,k,h,m,n;if(e==0)f=g=k=0;else switch(h=Math.floor(b*6),m=b*6-h,b=e*(1-c),n=e*(1-c*m),c=e*(1-c*(1-m)),h){case 1:f=n;g=e;k=b;break;case 2:f=b;g=e;k=c;break;case 3:f=b;g=n;k=e;break;case 4:f=c;g=b;k=e;break;case 5:f=e;g=b;k=n;break;case 6:case 0:f=e,g=c,k=b}this.setRGB(f,
M
Mr.doob 已提交
4
g,k)},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},clone:function(){return new THREE.Color(this.hex)}};THREE.Vector2=function(b,c){this.set(b||0,c||0)};
5 6
THREE.Vector2.prototype={set:function(b,c){this.x=b;this.y=c;return this},copy:function(b){this.x=b.x;this.y=b.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},add:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;return this},addSelf:function(b){this.x+=b.x;this.y+=b.y;return this},sub:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;return this},subSelf:function(b){this.x-=b.x;this.y-=b.y;return this},multiplyScalar:function(b){this.x*=b;this.y*=b;return this},divideScalar:function(b){b?
(this.x/=b,this.y/=b):this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(b){return Math.sqrt(this.distanceToSquared(b))},distanceToSquared:function(b){var c=this.x-b.x,b=this.y-b.y;return c*c+b*b},setLength:function(b){return this.normalize().multiplyScalar(b)},
M
Mr.doob 已提交
7 8
unit:function(){return this.normalize()},equals:function(b){return b.x==this.x&&b.y==this.y}};THREE.Vector3=function(b,c,e){this.set(b||0,c||0,e||0)};
THREE.Vector3.prototype={set:function(b,c,e){this.x=b;this.y=c;this.z=e;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;return this},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},add:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;this.z=b.z+c.z;return this},addSelf:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;return this},addScalar:function(b){this.x+=b;this.y+=b;this.z+=b;return this},sub:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;this.z=b.z-c.z;return this},subSelf:function(b){this.x-=
A
alteredq 已提交
9
b.x;this.y-=b.y;this.z-=b.z;return this},multiply:function(b,c){this.x=b.x*c.x;this.y=b.y*c.y;this.z=b.z*c.z;return this},multiplySelf:function(b){this.x*=b.x;this.y*=b.y;this.z*=b.z;return this},multiplyScalar:function(b){this.x*=b;this.y*=b;this.z*=b;return this},divideSelf:function(b){return this.divide(this,b)},divideScalar:function(b){b?(this.x/=b,this.y/=b,this.z/=b):this.set(0,0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*
10 11
b.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return this.x+this.y+this.z},normalize:function(){return this.divideScalar(this.length())},setLength:function(b){return this.normalize().multiplyScalar(b)},cross:function(b,c){this.x=b.y*c.z-b.z*c.y;this.y=b.z*c.x-b.x*c.z;this.z=b.x*c.y-b.y*c.x;return this},crossSelf:function(b){return this.set(this.y*b.z-this.z*b.y,this.z*b.x-this.x*b.z,this.x*
b.y-this.y*b.x)},distanceTo:function(b){return Math.sqrt(this.distanceToSquared(b))},distanceToSquared:function(b){return(new THREE.Vector3).sub(this,b).lengthSq()},setPositionFromMatrix:function(b){this.x=b.n14;this.y=b.n24;this.z=b.n34},setRotationFromMatrix:function(b){var c=Math.cos(this.y);this.y=Math.asin(b.n13);Math.abs(c)>1.0E-5?(this.x=Math.atan2(-b.n23/c,b.n33/c),this.z=Math.atan2(-b.n12/c,b.n11/c)):(this.x=0,this.z=Math.atan2(b.n21,b.n22))},isZero:function(){return this.lengthSq()<1.0E-4}};
M
Mr.doob 已提交
12 13
THREE.Vector4=function(b,c,e,f){this.set(b||0,c||0,e||0,f||1)};
THREE.Vector4.prototype={set:function(b,c,e,f){this.x=b;this.y=c;this.z=e;this.w=f;return this},copy:function(b){return this.set(b.x,b.y,b.z,b.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;this.z=b.z+c.z;this.w=b.w+c.w;return this},addSelf:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;this.w+=b.w;return this},sub:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;this.z=b.z-c.z;this.w=b.w-c.w;return this},subSelf:function(b){this.x-=
14 15
b.x;this.y-=b.y;this.z-=b.z;this.w-=b.w;return this},multiplyScalar:function(b){this.x*=b;this.y*=b;this.z*=b;this.w*=b;return this},divideScalar:function(b){b?(this.x/=b,this.y/=b,this.z/=b,this.w/=b):this.set(0,0,0,1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z+this.w*b.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},
setLength:function(b){return this.normalize().multiplyScalar(b)},lerpSelf:function(b,c){this.x+=(b.x-this.x)*c;this.y+=(b.y-this.y)*c;this.z+=(b.z-this.z)*c;this.w+=(b.w-this.w)*c;return this}};THREE.Ray=function(b,c){this.origin=b||new THREE.Vector3;this.direction=c||new THREE.Vector3};
M
Mr.doob 已提交
16
THREE.Ray.prototype={intersectScene:function(b){return this.intersectObjects(b.objects)},intersectObjects:function(b){var c,e,f=[];c=0;for(e=b.length;c<e;c++)f=f.concat(this.intersectObject(b[c]));f.sort(function(b,e){return b.distance-e.distance});return f},intersectObject:function(b){function c(b,e,c){var f,c=c.matrixWorld.getPosition();f=c.clone().subSelf(b).dot(e);b=b.clone().addSelf(e.clone().multiplyScalar(f));return c.distanceTo(b)}function e(b,e,c,f){var f=f.clone().subSelf(e),c=c.clone().subSelf(e),
17 18 19 20 21
g=b.clone().subSelf(e),b=f.dot(f),e=f.dot(c),f=f.dot(g),h=c.dot(c),c=c.dot(g),g=1/(b*h-e*e),h=(h*f-e*c)*g,b=(b*c-e*f)*g;return h>0&&b>0&&h+b<1}if(b instanceof THREE.Particle){var f=c(this.origin,this.direction,b);if(!f||f>b.scale.x)return[];return[{distance:f,point:b.position,face:null,object:b}]}else if(b instanceof THREE.Mesh){f=c(this.origin,this.direction,b);if(!f||f>b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)))return[];var g,k,h,m,n,p,o,t,v,u,w=b.geometry,
B=w.vertices,A=[],f=0;for(g=w.faces.length;f<g;f++)if(k=w.faces[f],v=this.origin.clone(),u=this.direction.clone(),p=b.matrixWorld,h=p.multiplyVector3(B[k.a].position.clone()),m=p.multiplyVector3(B[k.b].position.clone()),n=p.multiplyVector3(B[k.c].position.clone()),p=k instanceof THREE.Face4?p.multiplyVector3(B[k.d].position.clone()):null,o=b.matrixRotationWorld.multiplyVector3(k.normal.clone()),t=u.dot(o),b.doubleSided||(b.flipSided?t>0:t<0))if(o=o.dot((new THREE.Vector3).sub(h,v))/t,v=v.addSelf(u.multiplyScalar(o)),
k instanceof THREE.Face3)e(v,h,m,n)&&(k={distance:this.origin.distanceTo(v),point:v,face:k,object:b},A.push(k));else if(k instanceof THREE.Face4&&(e(v,h,m,p)||e(v,m,n,p)))k={distance:this.origin.distanceTo(v),point:v,face:k,object:b},A.push(k);return A}else return[]}};
THREE.Rectangle=function(){function b(){k=f-c;h=g-e}var c,e,f,g,k,h,m=!0;this.getX=function(){return c};this.getY=function(){return e};this.getWidth=function(){return k};this.getHeight=function(){return h};this.getLeft=function(){return c};this.getTop=function(){return e};this.getRight=function(){return f};this.getBottom=function(){return g};this.set=function(h,k,o,t){m=!1;c=h;e=k;f=o;g=t;b()};this.addPoint=function(h,k){m?(m=!1,c=h,e=k,f=h,g=k):(c=c<h?c:h,e=e<k?e:k,f=f>h?f:h,g=g>k?g:k);b()};this.add3Points=
function(h,k,o,t,v,u){m?(m=!1,c=h<o?h<v?h:v:o<v?o:v,e=k<t?k<u?k:u:t<u?t:u,f=h>o?h>v?h:v:o>v?o:v,g=k>t?k>u?k:u:t>u?t:u):(c=h<o?h<v?h<c?h:c:v<c?v:c:o<v?o<c?o:c:v<c?v:c,e=k<t?k<u?k<e?k:e:u<e?u:e:t<u?t<e?t:e:u<e?u:e,f=h>o?h>v?h>f?h:f:v>f?v:f:o>v?o>f?o:f:v>f?v:f,g=k>t?k>u?k>g?k:g:u>g?u:g:t>u?t>g?t:g:u>g?u:g);b()};this.addRectangle=function(h){m?(m=!1,c=h.getLeft(),e=h.getTop(),f=h.getRight(),g=h.getBottom()):(c=c<h.getLeft()?c:h.getLeft(),e=e<h.getTop()?e:h.getTop(),f=f>h.getRight()?f:h.getRight(),g=g>
M
Mr.doob 已提交
22
h.getBottom()?g:h.getBottom());b()};this.inflate=function(h){c-=h;e-=h;f+=h;g+=h;b()};this.minSelf=function(h){c=c>h.getLeft()?c:h.getLeft();e=e>h.getTop()?e:h.getTop();f=f<h.getRight()?f:h.getRight();g=g<h.getBottom()?g:h.getBottom();b()};this.instersects=function(b){return Math.min(f,b.getRight())-Math.max(c,b.getLeft())>=0&&Math.min(g,b.getBottom())-Math.max(e,b.getTop())>=0};this.empty=function(){m=!0;g=f=e=c=0;b()};this.isEmpty=function(){return m}};THREE.Matrix3=function(){this.m=[]};
23 24
THREE.Matrix3.prototype={transpose:function(){var b,c=this.m;b=c[1];c[1]=c[3];c[3]=b;b=c[2];c[2]=c[6];c[6]=b;b=c[5];c[5]=c[7];c[7]=b;return this},transposeIntoArray:function(b){var c=this.m;b[0]=c[0];b[1]=c[3];b[2]=c[6];b[3]=c[1];b[4]=c[4];b[5]=c[7];b[6]=c[2];b[7]=c[5];b[8]=c[8];return this}};THREE.Matrix4=function(b,c,e,f,g,k,h,m,n,p,o,t,v,u,w,B){this.set(b||1,c||0,e||0,f||0,g||0,k||1,h||0,m||0,n||0,p||0,o||1,t||0,v||0,u||0,w||0,B||1);this.flat=Array(16);this.m33=new THREE.Matrix3};
THREE.Matrix4.prototype={set:function(b,c,e,f,g,k,h,m,n,p,o,t,v,u,w,B){this.n11=b;this.n12=c;this.n13=e;this.n14=f;this.n21=g;this.n22=k;this.n23=h;this.n24=m;this.n31=n;this.n32=p;this.n33=o;this.n34=t;this.n41=v;this.n42=u;this.n43=w;this.n44=B;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(b){this.set(b.n11,b.n12,b.n13,b.n14,b.n21,b.n22,b.n23,b.n24,b.n31,b.n32,b.n33,b.n34,b.n41,b.n42,b.n43,b.n44);return this},lookAt:function(b,c,e){var f=THREE.Matrix4.__v1,
M
Mr.doob 已提交
25
g=THREE.Matrix4.__v2,k=THREE.Matrix4.__v3;k.sub(b,c).normalize();if(k.length()===0)k.z=1;f.cross(e,k).normalize();f.length()===0&&(k.x+=1.0E-4,f.cross(e,k).normalize());g.cross(k,f).normalize();this.n11=f.x;this.n12=g.x;this.n13=k.x;this.n21=f.y;this.n22=g.y;this.n23=k.y;this.n31=f.z;this.n32=g.z;this.n33=k.z;return this},multiplyVector3:function(b){var c=b.x,e=b.y,f=b.z,g=1/(this.n41*c+this.n42*e+this.n43*f+this.n44);b.x=(this.n11*c+this.n12*e+this.n13*f+this.n14)*g;b.y=(this.n21*c+this.n22*e+this.n23*
M
Mr.doob 已提交
26
f+this.n24)*g;b.z=(this.n31*c+this.n32*e+this.n33*f+this.n34)*g;return b},multiplyVector4:function(b){var c=b.x,e=b.y,f=b.z,g=b.w;b.x=this.n11*c+this.n12*e+this.n13*f+this.n14*g;b.y=this.n21*c+this.n22*e+this.n23*f+this.n24*g;b.z=this.n31*c+this.n32*e+this.n33*f+this.n34*g;b.w=this.n41*c+this.n42*e+this.n43*f+this.n44*g;return b},rotateAxis:function(b){var c=b.x,e=b.y,f=b.z;b.x=c*this.n11+e*this.n12+f*this.n13;b.y=c*this.n21+e*this.n22+f*this.n23;b.z=c*this.n31+e*this.n32+f*this.n33;b.normalize();
27 28
return b},crossVector:function(b){var c=new THREE.Vector4;c.x=this.n11*b.x+this.n12*b.y+this.n13*b.z+this.n14*b.w;c.y=this.n21*b.x+this.n22*b.y+this.n23*b.z+this.n24*b.w;c.z=this.n31*b.x+this.n32*b.y+this.n33*b.z+this.n34*b.w;c.w=b.w?this.n41*b.x+this.n42*b.y+this.n43*b.z+this.n44*b.w:1;return c},multiply:function(b,c){var e=b.n11,f=b.n12,g=b.n13,k=b.n14,h=b.n21,m=b.n22,n=b.n23,p=b.n24,o=b.n31,t=b.n32,v=b.n33,u=b.n34,w=b.n41,B=b.n42,A=b.n43,y=b.n44,G=c.n11,z=c.n12,C=c.n13,H=c.n14,D=c.n21,Q=c.n22,
J=c.n23,F=c.n24,I=c.n31,S=c.n32,K=c.n33,ea=c.n34,j=c.n41,ca=c.n42,T=c.n43,Z=c.n44;this.n11=e*G+f*D+g*I+k*j;this.n12=e*z+f*Q+g*S+k*ca;this.n13=e*C+f*J+g*K+k*T;this.n14=e*H+f*F+g*ea+k*Z;this.n21=h*G+m*D+n*I+p*j;this.n22=h*z+m*Q+n*S+p*ca;this.n23=h*C+m*J+n*K+p*T;this.n24=h*H+m*F+n*ea+p*Z;this.n31=o*G+t*D+v*I+u*j;this.n32=o*z+t*Q+v*S+u*ca;this.n33=o*C+t*J+v*K+u*T;this.n34=o*H+t*F+v*ea+u*Z;this.n41=w*G+B*D+A*I+y*j;this.n42=w*z+B*Q+A*S+y*ca;this.n43=w*C+B*J+A*K+y*T;this.n44=w*H+B*F+A*ea+y*Z;return this},
M
Mr.doob 已提交
29
multiplyToArray:function(b,c,e){this.multiply(b,c);e[0]=this.n11;e[1]=this.n21;e[2]=this.n31;e[3]=this.n41;e[4]=this.n12;e[5]=this.n22;e[6]=this.n32;e[7]=this.n42;e[8]=this.n13;e[9]=this.n23;e[10]=this.n33;e[11]=this.n43;e[12]=this.n14;e[13]=this.n24;e[14]=this.n34;e[15]=this.n44;return this},multiplySelf:function(b){this.multiply(this,b);return this},multiplyScalar:function(b){this.n11*=b;this.n12*=b;this.n13*=b;this.n14*=b;this.n21*=b;this.n22*=b;this.n23*=b;this.n24*=b;this.n31*=b;this.n32*=b;
30
this.n33*=b;this.n34*=b;this.n41*=b;this.n42*=b;this.n43*=b;this.n44*=b;return this},determinant:function(){var b=this.n11,c=this.n12,e=this.n13,f=this.n14,g=this.n21,k=this.n22,h=this.n23,m=this.n24,n=this.n31,p=this.n32,o=this.n33,t=this.n34,v=this.n41,u=this.n42,w=this.n43,B=this.n44;return f*h*p*v-e*m*p*v-f*k*o*v+c*m*o*v+e*k*t*v-c*h*t*v-f*h*n*u+e*m*n*u+f*g*o*u-b*m*o*u-e*g*t*u+b*h*t*u+f*k*n*w-c*m*n*w-f*g*p*w+b*m*p*w+c*g*t*w-b*k*t*w-e*k*n*B+c*h*n*B+e*g*p*B-b*h*p*B-c*g*o*B+b*k*o*B},transpose:function(){var b;
M
Mr.doob 已提交
31 32 33 34
b=this.n21;this.n21=this.n12;this.n12=b;b=this.n31;this.n31=this.n13;this.n13=b;b=this.n32;this.n32=this.n23;this.n23=b;b=this.n41;this.n41=this.n14;this.n14=b;b=this.n42;this.n42=this.n24;this.n24=b;b=this.n43;this.n43=this.n34;this.n43=b;return this},clone:function(){var b=new THREE.Matrix4;b.n11=this.n11;b.n12=this.n12;b.n13=this.n13;b.n14=this.n14;b.n21=this.n21;b.n22=this.n22;b.n23=this.n23;b.n24=this.n24;b.n31=this.n31;b.n32=this.n32;b.n33=this.n33;b.n34=this.n34;b.n41=this.n41;b.n42=this.n42;
b.n43=this.n43;b.n44=this.n44;return b},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(b){b[0]=this.n11;b[1]=this.n21;b[2]=this.n31;
b[3]=this.n41;b[4]=this.n12;b[5]=this.n22;b[6]=this.n32;b[7]=this.n42;b[8]=this.n13;b[9]=this.n23;b[10]=this.n33;b[11]=this.n43;b[12]=this.n14;b[13]=this.n24;b[14]=this.n34;b[15]=this.n44;return b},flattenToArrayOffset:function(b,c){b[c]=this.n11;b[c+1]=this.n21;b[c+2]=this.n31;b[c+3]=this.n41;b[c+4]=this.n12;b[c+5]=this.n22;b[c+6]=this.n32;b[c+7]=this.n42;b[c+8]=this.n13;b[c+9]=this.n23;b[c+10]=this.n33;b[c+11]=this.n43;b[c+12]=this.n14;b[c+13]=this.n24;b[c+14]=this.n34;b[c+15]=this.n44;return b},
setTranslation:function(b,c,e){this.set(1,0,0,b,0,1,0,c,0,0,1,e,0,0,0,1);return this},setScale:function(b,c,e){this.set(b,0,0,0,0,c,0,0,0,0,e,0,0,0,0,1);return this},setRotationX:function(b){var c=Math.cos(b),b=Math.sin(b);this.set(1,0,0,0,0,c,-b,0,0,b,c,0,0,0,0,1);return this},setRotationY:function(b){var c=Math.cos(b),b=Math.sin(b);this.set(c,0,b,0,0,1,0,0,-b,0,c,0,0,0,0,1);return this},setRotationZ:function(b){var c=Math.cos(b),b=Math.sin(b);this.set(c,-b,0,0,b,c,0,0,0,0,1,0,0,0,0,1);return this},
35 36 37 38 39
setRotationAxis:function(b,c){var e=Math.cos(c),f=Math.sin(c),g=1-e,k=b.x,h=b.y,m=b.z,n=g*k,p=g*h;this.set(n*k+e,n*h-f*m,n*m+f*h,0,n*h+f*m,p*h+e,p*m-f*k,0,n*m-f*h,p*m+f*k,g*m*m+e,0,0,0,0,1);return this},setPosition:function(b){this.n14=b.x;this.n24=b.y;this.n34=b.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX=new THREE.Vector3;this.columnX.set(this.n11,
this.n21,this.n31);return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(b,c){var e=b.x,f=b.y,g=b.z,k=Math.cos(e),e=Math.sin(e),h=Math.cos(f),f=Math.sin(f),m=Math.cos(g),g=Math.sin(g);switch(c){case "YXZ":var n=h*m,p=h*g,o=f*m,t=f*g;
this.n11=n+t*e;this.n12=o*e-p;this.n13=k*f;this.n21=k*g;this.n22=k*m;this.n23=-e;this.n31=p*e-o;this.n32=t+n*e;this.n33=k*h;break;case "ZXY":n=h*m;p=h*g;o=f*m;t=f*g;this.n11=n-t*e;this.n12=-k*g;this.n13=o+p*e;this.n21=p+o*e;this.n22=k*m;this.n23=t-n*e;this.n31=-k*f;this.n32=e;this.n33=k*h;break;case "ZYX":n=k*m;p=k*g;o=e*m;t=e*g;this.n11=h*m;this.n12=o*f-p;this.n13=n*f+t;this.n21=h*g;this.n22=t*f+n;this.n23=p*f-o;this.n31=-f;this.n32=e*h;this.n33=k*h;break;case "YZX":n=k*h;p=k*f;o=e*h;t=e*f;this.n11=
h*m;this.n12=t-n*g;this.n13=o*g+p;this.n21=g;this.n22=k*m;this.n23=-e*m;this.n31=-f*m;this.n32=p*g+o;this.n33=n-t*g;break;case "XZY":n=k*h;p=k*f;o=e*h;t=e*f;this.n11=h*m;this.n12=-g;this.n13=f*m;this.n21=n*g+t;this.n22=k*m;this.n23=p*g-o;this.n31=o*g-p;this.n32=e*m;this.n33=t*g+n;break;default:n=k*m,p=k*g,o=e*m,t=e*g,this.n11=h*m,this.n12=-h*g,this.n13=f,this.n21=p+o*f,this.n22=n-t*f,this.n23=-e*h,this.n31=t-n*f,this.n32=o+p*f,this.n33=k*h}return this},setRotationFromQuaternion:function(b){var c=
b.x,e=b.y,f=b.z,g=b.w,k=c+c,h=e+e,m=f+f,b=c*k,n=c*h;c*=m;var p=e*h;e*=m;f*=m;k*=g;h*=g;g*=m;this.n11=1-(p+f);this.n12=n-g;this.n13=c+h;this.n21=n+g;this.n22=1-(b+f);this.n23=e-k;this.n31=c-h;this.n32=e+k;this.n33=1-(b+p);return this},scale:function(b){var c=b.x,e=b.y,b=b.z;this.n11*=c;this.n12*=e;this.n13*=b;this.n21*=c;this.n22*=e;this.n23*=b;this.n31*=c;this.n32*=e;this.n33*=b;this.n41*=c;this.n42*=e;this.n43*=b;return this},extractPosition:function(b){this.n14=b.n14;this.n24=b.n24;this.n34=b.n34},
M
Mr.doob 已提交
40
extractRotation:function(b,c){var e=1/c.x,f=1/c.y,g=1/c.z;this.n11=b.n11*e;this.n21=b.n21*e;this.n31=b.n31*e;this.n12=b.n12*f;this.n22=b.n22*f;this.n32=b.n32*f;this.n13=b.n13*g;this.n23=b.n23*g;this.n33=b.n33*g}};
41 42 43
THREE.Matrix4.makeInvert=function(b,c){var e=b.n11,f=b.n12,g=b.n13,k=b.n14,h=b.n21,m=b.n22,n=b.n23,p=b.n24,o=b.n31,t=b.n32,v=b.n33,u=b.n34,w=b.n41,B=b.n42,A=b.n43,y=b.n44;c===void 0&&(c=new THREE.Matrix4);c.n11=n*u*B-p*v*B+p*t*A-m*u*A-n*t*y+m*v*y;c.n12=k*v*B-g*u*B-k*t*A+f*u*A+g*t*y-f*v*y;c.n13=g*p*B-k*n*B+k*m*A-f*p*A-g*m*y+f*n*y;c.n14=k*n*t-g*p*t-k*m*v+f*p*v+g*m*u-f*n*u;c.n21=p*v*w-n*u*w-p*o*A+h*u*A+n*o*y-h*v*y;c.n22=g*u*w-k*v*w+k*o*A-e*u*A-g*o*y+e*v*y;c.n23=k*n*w-g*p*w-k*h*A+e*p*A+g*h*y-e*n*y;c.n24=
g*p*o-k*n*o+k*h*v-e*p*v-g*h*u+e*n*u;c.n31=m*u*w-p*t*w+p*o*B-h*u*B-m*o*y+h*t*y;c.n32=k*t*w-f*u*w-k*o*B+e*u*B+f*o*y-e*t*y;c.n33=g*p*w-k*m*w+k*h*B-e*p*B-f*h*y+e*m*y;c.n34=k*m*o-f*p*o-k*h*t+e*p*t+f*h*u-e*m*u;c.n41=n*t*w-m*v*w-n*o*B+h*v*B+m*o*A-h*t*A;c.n42=f*v*w-g*t*w+g*o*B-e*v*B-f*o*A+e*t*A;c.n43=g*m*w-f*n*w-g*h*B+e*n*B+f*h*A-e*m*A;c.n44=f*n*o-g*m*o+g*h*t-e*n*t-f*h*v+e*m*v;c.multiplyScalar(1/b.determinant());return c};
THREE.Matrix4.makeInvert3x3=function(b){var c=b.m33,e=c.m,f=b.n33*b.n22-b.n32*b.n23,g=-b.n33*b.n21+b.n31*b.n23,k=b.n32*b.n21-b.n31*b.n22,h=-b.n33*b.n12+b.n32*b.n13,m=b.n33*b.n11-b.n31*b.n13,n=-b.n32*b.n11+b.n31*b.n12,p=b.n23*b.n12-b.n22*b.n13,o=-b.n23*b.n11+b.n21*b.n13,t=b.n22*b.n11-b.n21*b.n12,b=b.n11*f+b.n21*h+b.n31*p;b==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");b=1/b;e[0]=b*f;e[1]=b*g;e[2]=b*k;e[3]=b*h;e[4]=b*m;e[5]=b*n;e[6]=b*p;e[7]=b*o;e[8]=b*t;return c};
M
Mr.doob 已提交
44
THREE.Matrix4.makeFrustum=function(b,c,e,f,g,k){var h;h=new THREE.Matrix4;h.n11=2*g/(c-b);h.n12=0;h.n13=(c+b)/(c-b);h.n14=0;h.n21=0;h.n22=2*g/(f-e);h.n23=(f+e)/(f-e);h.n24=0;h.n31=0;h.n32=0;h.n33=-(k+g)/(k-g);h.n34=-2*k*g/(k-g);h.n41=0;h.n42=0;h.n43=-1;h.n44=0;return h};THREE.Matrix4.makePerspective=function(b,c,e,f){var g,b=e*Math.tan(b*Math.PI/360);g=-b;return THREE.Matrix4.makeFrustum(g*c,b*c,g,b,e,f)};
45
THREE.Matrix4.makeOrtho=function(b,c,e,f,g,k){var h,m,n,p;h=new THREE.Matrix4;m=c-b;n=e-f;p=k-g;h.n11=2/m;h.n12=0;h.n13=0;h.n14=-((c+b)/m);h.n21=0;h.n22=2/n;h.n23=0;h.n24=-((e+f)/n);h.n31=0;h.n32=0;h.n33=-2/p;h.n34=-((k+g)/p);h.n41=0;h.n42=0;h.n43=0;h.n44=1;return h};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;
46 47 48
THREE.Object3D=function(){this.parent=void 0;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.eulerOrder="XYZ";this.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=this.dynamic=!1;this.renderDepth=null;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion;
this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this._vector=new THREE.Vector3;this.name=""};
THREE.Object3D.prototype={translate:function(b,c){this.matrix.rotateAxis(c);this.position.addSelf(c.multiplyScalar(b))},translateX:function(b){this.translate(b,this._vector.set(1,0,0))},translateY:function(b){this.translate(b,this._vector.set(0,1,0))},translateZ:function(b){this.translate(b,this._vector.set(0,0,1))},lookAt:function(b){this.matrix.lookAt(b,this.position,this.up);this.rotationAutoUpdate&&this.rotation.setRotationFromMatrix(this.matrix)},addChild:function(b){if(this.children.indexOf(b)===
M
Mr.doob 已提交
49 50 51
-1){b.parent!==void 0&&b.parent.removeChild(b);b.parent=this;this.children.push(b);for(var c=this;c.parent!==void 0;)c=c.parent;c!==void 0&&c instanceof THREE.Scene&&c.addChildRecurse(b)}},removeChild:function(b){var c=this.children.indexOf(b);if(c!==-1)b.parent=void 0,this.children.splice(c,1)},getChildByName:function(b,c){var e,f,g;e=0;for(f=this.children.length;e<f;e++){g=this.children[e];if(g.name===b)return g;if(c&&(g=g.getChildByName(b,c),g!==void 0))return g}},updateMatrix:function(){this.matrix.setPosition(this.position);
this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation,this.eulerOrder);if(this.scale.x!==1||this.scale.y!==1||this.scale.z!==1)this.matrix.scale(this.scale),this.boundRadiusScale=Math.max(this.scale.x,Math.max(this.scale.y,this.scale.z));this.matrixWorldNeedsUpdate=!0},update:function(b,c,e){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||c)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),
this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matrixWorldNeedsUpdate=!1,c=!0;for(var b=0,f=this.children.length;b<f;b++)this.children[b].update(this.matrixWorld,c,e)}};THREE.Quaternion=function(b,c,e,f){this.set(b||0,c||0,e||0,f!==void 0?f:1)};
M
Mr.doob 已提交
52
THREE.Quaternion.prototype={set:function(b,c,e,f){this.x=b;this.y=c;this.z=e;this.w=f;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;this.w=b.w;return this},setFromEuler:function(b){var c=0.5*Math.PI/360,e=b.x*c,f=b.y*c,g=b.z*c,b=Math.cos(f),f=Math.sin(f),c=Math.cos(-g),g=Math.sin(-g),k=Math.cos(e),e=Math.sin(e),h=b*c,m=f*g;this.w=h*k-m*e;this.x=h*e+m*k;this.y=f*c*k+b*g*e;this.z=b*g*k-f*c*e;return this},setFromAxisAngle:function(b,c){var e=c/2,f=Math.sin(e);this.x=b.x*f;this.y=b.y*
M
Mr.doob 已提交
53
f;this.z=b.z*f;this.w=Math.cos(e);return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var b=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);b==0?this.w=this.z=this.y=this.x=0:(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},
54 55
multiplySelf:function(b){var c=this.x,e=this.y,f=this.z,g=this.w,k=b.x,h=b.y,m=b.z,b=b.w;this.x=c*b+g*k+e*m-f*h;this.y=e*b+g*h+f*k-c*m;this.z=f*b+g*m+c*h-e*k;this.w=g*b-c*k-e*h-f*m;return this},multiply:function(b,c){this.x=b.x*c.w+b.y*c.z-b.z*c.y+b.w*c.x;this.y=-b.x*c.z+b.y*c.w+b.z*c.x+b.w*c.y;this.z=b.x*c.y-b.y*c.x+b.z*c.w+b.w*c.z;this.w=-b.x*c.x-b.y*c.y-b.z*c.z+b.w*c.w;return this},multiplyVector3:function(b,c){c||(c=b);var e=b.x,f=b.y,g=b.z,k=this.x,h=this.y,m=this.z,n=this.w,p=n*e+h*g-m*f,o=
n*f+m*e-k*g,t=n*g+k*f-h*e,e=-k*e-h*f-m*g;c.x=p*n+e*-k+o*-m-t*-h;c.y=o*n+e*-h+t*-k-p*-m;c.z=t*n+e*-m+p*-h-o*-k;return c}};
A
alteredq 已提交
56
THREE.Quaternion.slerp=function(b,c,e,f){var g=b.w*c.w+b.x*c.x+b.y*c.y+b.z*c.z;if(Math.abs(g)>=1)return e.w=b.w,e.x=b.x,e.y=b.y,e.z=b.z,e;var k=Math.acos(g),h=Math.sqrt(1-g*g);if(Math.abs(h)<0.0010)return e.w=0.5*(b.w+c.w),e.x=0.5*(b.x+c.x),e.y=0.5*(b.y+c.y),e.z=0.5*(b.z+c.z),e;g=Math.sin((1-f)*k)/h;f=Math.sin(f*k)/h;e.w=b.w*g+c.w*f;e.x=b.x*g+c.x*f;e.y=b.y*g+c.y*f;e.z=b.z*g+c.z*f;return e};THREE.Vertex=function(b){this.position=b||new THREE.Vector3};
M
Mr.doob 已提交
57 58
THREE.Face3=function(b,c,e,f,g,k){this.a=b;this.b=c;this.c=e;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=k instanceof Array?k:[k];this.centroid=new THREE.Vector3};
THREE.Face4=function(b,c,e,f,g,k,h){this.a=b;this.b=c;this.c=e;this.d=f;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.color=k instanceof THREE.Color?k:new THREE.Color;this.vertexColors=k instanceof Array?k:[];this.vertexTangents=[];this.materials=h instanceof Array?h:[h];this.centroid=new THREE.Vector3};THREE.UV=function(b,c){this.set(b||0,c||0)};
59
THREE.UV.prototype={set:function(b,c){this.u=b;this.v=c;return this},copy:function(b){this.set(b.u,b.v);return this}};THREE.Geometry=function(){this.id="Geometry"+THREE.GeometryIdCounter++;this.vertices=[];this.colors=[];this.faces=[];this.edges=[];this.faceUvs=[[]];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphColors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.hasTangents=!1};
M
Mr.doob 已提交
60
THREE.Geometry.prototype={computeCentroids:function(){var b,c,e;b=0;for(c=this.faces.length;b<c;b++)e=this.faces[b],e.centroid.set(0,0,0),e instanceof THREE.Face3?(e.centroid.addSelf(this.vertices[e.a].position),e.centroid.addSelf(this.vertices[e.b].position),e.centroid.addSelf(this.vertices[e.c].position),e.centroid.divideScalar(3)):e instanceof THREE.Face4&&(e.centroid.addSelf(this.vertices[e.a].position),e.centroid.addSelf(this.vertices[e.b].position),e.centroid.addSelf(this.vertices[e.c].position),
M
Mr.doob 已提交
61
e.centroid.addSelf(this.vertices[e.d].position),e.centroid.divideScalar(4))},computeFaceNormals:function(b){var c,e,f,g,k,h,m=new THREE.Vector3,n=new THREE.Vector3;f=0;for(g=this.faces.length;f<g;f++){k=this.faces[f];if(b&&k.vertexNormals.length){m.set(0,0,0);c=0;for(e=k.vertexNormals.length;c<e;c++)m.addSelf(k.vertexNormals[c]);m.divideScalar(3)}else c=this.vertices[k.a],e=this.vertices[k.b],h=this.vertices[k.c],m.sub(h.position,e.position),n.sub(c.position,e.position),m.crossSelf(n);m.isZero()||
M
Mr.doob 已提交
62
m.normalize();k.normal.copy(m)}},computeVertexNormals:function(){var b,c,e,f;if(this.__tmpVertices==void 0){f=this.__tmpVertices=Array(this.vertices.length);b=0;for(c=this.vertices.length;b<c;b++)f[b]=new THREE.Vector3;b=0;for(c=this.faces.length;b<c;b++)if(e=this.faces[b],e instanceof THREE.Face3)e.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(e instanceof THREE.Face4)e.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}else{f=
M
Mr.doob 已提交
63
this.__tmpVertices;b=0;for(c=this.vertices.length;b<c;b++)f[b].set(0,0,0)}b=0;for(c=this.faces.length;b<c;b++)e=this.faces[b],e instanceof THREE.Face3?(f[e.a].addSelf(e.normal),f[e.b].addSelf(e.normal),f[e.c].addSelf(e.normal)):e instanceof THREE.Face4&&(f[e.a].addSelf(e.normal),f[e.b].addSelf(e.normal),f[e.c].addSelf(e.normal),f[e.d].addSelf(e.normal));b=0;for(c=this.vertices.length;b<c;b++)f[b].normalize();b=0;for(c=this.faces.length;b<c;b++)e=this.faces[b],e instanceof THREE.Face3?(e.vertexNormals[0].copy(f[e.a]),
64 65
e.vertexNormals[1].copy(f[e.b]),e.vertexNormals[2].copy(f[e.c])):e instanceof THREE.Face4&&(e.vertexNormals[0].copy(f[e.a]),e.vertexNormals[1].copy(f[e.b]),e.vertexNormals[2].copy(f[e.c]),e.vertexNormals[3].copy(f[e.d]))},computeTangents:function(){function b(b,e,c,j,f,g,k){m=b.vertices[e].position;n=b.vertices[c].position;p=b.vertices[j].position;o=h[f];t=h[g];v=h[k];u=n.x-m.x;w=p.x-m.x;B=n.y-m.y;A=p.y-m.y;y=n.z-m.z;G=p.z-m.z;z=t.u-o.u;C=v.u-o.u;H=t.v-o.v;D=v.v-o.v;Q=1/(z*D-C*H);S.set((D*u-H*w)*
Q,(D*B-H*A)*Q,(D*y-H*G)*Q);K.set((z*w-C*u)*Q,(z*A-C*B)*Q,(z*G-C*y)*Q);F[e].addSelf(S);F[c].addSelf(S);F[j].addSelf(S);I[e].addSelf(K);I[c].addSelf(K);I[j].addSelf(K)}var c,e,f,g,k,h,m,n,p,o,t,v,u,w,B,A,y,G,z,C,H,D,Q,J,F=[],I=[],S=new THREE.Vector3,K=new THREE.Vector3,ea=new THREE.Vector3,j=new THREE.Vector3,ca=new THREE.Vector3;c=0;for(e=this.vertices.length;c<e;c++)F[c]=new THREE.Vector3,I[c]=new THREE.Vector3;c=0;for(e=this.faces.length;c<e;c++)k=this.faces[c],h=this.faceVertexUvs[0][c],k instanceof
M
Mr.doob 已提交
66
THREE.Face3?b(this,k.a,k.b,k.c,0,1,2):k instanceof THREE.Face4&&(b(this,k.a,k.b,k.c,0,1,2),b(this,k.a,k.b,k.d,0,1,3));var T=["a","b","c","d"];c=0;for(e=this.faces.length;c<e;c++){k=this.faces[c];for(f=0;f<k.vertexNormals.length;f++)ca.copy(k.vertexNormals[f]),g=k[T[f]],J=F[g],ea.copy(J),ea.subSelf(ca.multiplyScalar(ca.dot(J))).normalize(),j.cross(k.vertexNormals[f],J),g=j.dot(I[g]),g=g<0?-1:1,k.vertexTangents[f]=new THREE.Vector4(ea.x,ea.y,ea.z,g)}this.hasTangents=!0},computeBoundingBox:function(){var b;
M
Mr.doob 已提交
67 68
if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var c=1,e=this.vertices.length;c<e;c++){b=this.vertices[c];if(b.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=b.position.x;else if(b.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=b.position.x;if(b.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=b.position.y;
else if(b.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=b.position.y;if(b.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=b.position.z;else if(b.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=b.position.z}}},computeBoundingSphere:function(){for(var b=0,c=0,e=this.vertices.length;c<e;c++)b=Math.max(b,this.vertices[c].position.length());this.boundingSphere={radius:b}},computeEdgeFaces:function(){function b(b,e){return Math.min(b,e)+"_"+Math.max(b,e)}function c(b,e,c){b[e]===
M
Mr.doob 已提交
69 70
void 0?(b[e]={set:{},array:[]},b[e].set[c]=1,b[e].array.push(c)):b[e].set[c]===void 0&&(b[e].set[c]=1,b[e].array.push(c))}var e,f,g,k,h,m={};e=0;for(f=this.faces.length;e<f;e++)h=this.faces[e],h instanceof THREE.Face3?(g=b(h.a,h.b),c(m,g,e),g=b(h.b,h.c),c(m,g,e),g=b(h.a,h.c),c(m,g,e)):h instanceof THREE.Face4&&(g=b(h.b,h.d),c(m,g,e),g=b(h.a,h.b),c(m,g,e),g=b(h.a,h.d),c(m,g,e),g=b(h.b,h.c),c(m,g,e),g=b(h.c,h.d),c(m,g,e));e=0;for(f=this.edges.length;e<f;e++){h=this.edges[e];g=h.vertexIndices[0];k=h.vertexIndices[1];
h.faceIndices=m[b(g,k)].array;for(g=0;g<h.faceIndices.length;g++)k=h.faceIndices[g],h.faces.push(this.faces[k])}}};THREE.GeometryIdCounter=0;
71 72
THREE.Spline=function(b){function c(b,e,c,f,g,h,k){b=(c-b)*0.5;f=(f-e)*0.5;return(2*(e-c)+b+f)*k+(-3*(e-c)-2*b-f)*h+b*g+e}this.points=b;var e=[],f={x:0,y:0,z:0},g,k,h,m,n,p,o,t,v;this.initFromArray=function(b){this.points=[];for(var e=0;e<b.length;e++)this.points[e]={x:b[e][0],y:b[e][1],z:b[e][2]}};this.getPoint=function(b){g=(this.points.length-1)*b;k=Math.floor(g);h=g-k;e[0]=k==0?k:k-1;e[1]=k;e[2]=k>this.points.length-2?k:k+1;e[3]=k>this.points.length-3?k:k+2;p=this.points[e[0]];o=this.points[e[1]];
t=this.points[e[2]];v=this.points[e[3]];m=h*h;n=h*m;f.x=c(p.x,o.x,t.x,v.x,h,m,n);f.y=c(p.y,o.y,t.y,v.y,h,m,n);f.z=c(p.z,o.z,t.z,v.z,h,m,n);return f};this.getControlPointsArray=function(){var b,e,c=this.points.length,f=[];for(b=0;b<c;b++)e=this.points[b],f[b]=[e.x,e.y,e.z];return f};this.getLength=function(b){var e,c,f=e=e=0,g=new THREE.Vector3,h=new THREE.Vector3,k=[],m=0;k[0]=0;b||(b=100);c=this.points.length*b;g.copy(this.points[0]);for(b=1;b<c;b++)e=b/c,position=this.getPoint(e),h.copy(position),
M
Mr.doob 已提交
73 74
m+=h.distanceTo(g),g.copy(position),e*=this.points.length-1,e=Math.floor(e),e!=f&&(k[e]=m,f=e);k[k.length]=m;return{chunks:k,total:m}};this.reparametrizeByArcLength=function(b){var e,c,f,g,h,k,m=[],n=new THREE.Vector3,o=this.getLength();m.push(n.copy(this.points[0]).clone());for(e=1;e<this.points.length;e++){c=o.chunks[e]-o.chunks[e-1];k=Math.ceil(b*c/o.total);g=(e-1)/(this.points.length-1);h=e/(this.points.length-1);for(c=1;c<k-1;c++)f=g+c*(1/k)*(h-g),position=this.getPoint(f),m.push(n.copy(position).clone());
m.push(n.copy(this.points[e]).clone())}this.points=m}};THREE.Edge=function(b,c,e,f){this.vertices=[b,c];this.vertexIndices=[e,f];this.faces=[];this.faceIndices=[]};THREE.Camera=function(b,c,e,f,g){THREE.Object3D.call(this);this.fov=b||50;this.aspect=c||1;this.near=e||0.1;this.far=f||2E3;this.target=g||new THREE.Object3D;this.useTarget=!0;this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=null;this.updateProjectionMatrix()};THREE.Camera.prototype=new THREE.Object3D;
75
THREE.Camera.prototype.constructor=THREE.Camera;THREE.Camera.prototype.supr=THREE.Object3D.prototype;THREE.Camera.prototype.translate=function(b,c){this.matrix.rotateAxis(c);c.multiplyScalar(b);this.position.addSelf(c);this.target.position.addSelf(c)};
M
Mr.doob 已提交
76
THREE.Camera.prototype.updateProjectionMatrix=function(){if(this.fullWidth){var b=this.fullWidth/this.fullHeight,c=Math.tan(this.fov*Math.PI/360)*this.near,e=-c,f=b*e,b=Math.abs(b*c-f),e=Math.abs(c-e);this.projectionMatrix=THREE.Matrix4.makeFrustum(f+this.x*b/this.fullWidth,f+(this.x+this.width)*b/this.fullWidth,c-(this.y+this.height)*e/this.fullHeight,c-this.y*e/this.fullHeight,this.near,this.far)}else this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};
M
Mr.doob 已提交
77
THREE.Camera.prototype.setViewOffset=function(b,c,e,f,g,k){this.fullWidth=b;this.fullHeight=c;this.x=e;this.y=f;this.width=g;this.height=k;this.updateProjectionMatrix()};
M
Mr.doob 已提交
78 79 80 81 82 83
THREE.Camera.prototype.update=function(b,c,e){if(this.useTarget)this.matrix.lookAt(this.position,this.target.position,this.up),this.matrix.setPosition(this.position),b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse),c=!0;else if(this.matrixAutoUpdate&&this.updateMatrix(),c||this.matrixWorldNeedsUpdate)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=
!1,c=!0,THREE.Matrix4.makeInvert(this.matrixWorld,this.matrixWorldInverse);for(b=0;b<this.children.length;b++)this.children[b].update(this.matrixWorld,c,e)};THREE.Light=function(b){THREE.Object3D.call(this);this.color=new THREE.Color(b)};THREE.Light.prototype=new THREE.Object3D;THREE.Light.prototype.constructor=THREE.Light;THREE.Light.prototype.supr=THREE.Object3D.prototype;THREE.AmbientLight=function(b){THREE.Light.call(this,b)};THREE.AmbientLight.prototype=new THREE.Light;
THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(b,c,e,f){THREE.Light.call(this,b);this.position=new THREE.Vector3(0,1,0);this.intensity=c||1;this.distance=e||0;this.castShadow=f!==void 0?f:!1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;THREE.PointLight=function(b,c,e){THREE.Light.call(this,b);this.position=new THREE.Vector3;this.intensity=c||1;this.distance=e||0};
THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;THREE.LensFlare=function(b,c,e,f){THREE.Object3D.call(this);this.positionScreen=new THREE.Vector3;this.lensFlares=[];this.customUpdateCallback=void 0;b!==void 0&&this.add(b,c,e,f)};THREE.LensFlare.prototype=new THREE.Object3D;THREE.LensFlare.prototype.constructor=THREE.LensFlare;THREE.LensFlare.prototype.supr=THREE.Object3D.prototype;
THREE.LensFlare.prototype.add=function(b,c,e,f){c===void 0&&(c=-1);e===void 0&&(e=0);if(f===void 0)f=THREE.BillboardBlending;e=Math.min(e,Math.max(0,e));this.lensFlares.push({texture:b,size:c,distance:e,x:0,y:0,z:0,scale:1,rotation:1,opacity:1,blending:f})};
THREE.LensFlare.prototype.updateLensFlares=function(){var b,c=this.lensFlares.length,e,f=-this.positionScreen.x*2,g=-this.positionScreen.y*2;for(b=0;b<c;b++)e=this.lensFlares[b],e.x=this.positionScreen.x+f*e.distance,e.y=this.positionScreen.y+g*e.distance,e.wantedRotation=e.x*Math.PI*0.25,e.rotation+=(e.wantedRotation-e.rotation)*0.25};
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
THREE.Material=function(b){this.id=THREE.MaterialCounter.value++;b=b||{};this.opacity=b.opacity!==void 0?b.opacity:1;this.transparent=b.transparent!==void 0?b.transparent:!1;this.blending=b.blending!==void 0?b.blending:THREE.NormalBlending;this.depthTest=b.depthTest!==void 0?b.depthTest:!0;this.polygonOffset=b.polygonOffset!==void 0?b.polygonOffset:!1;this.polygonOffsetFactor=b.polygonOffsetFactor!==void 0?b.polygonOffsetFactor:0;this.polygonOffsetUnits=b.polygonOffsetUnits!==void 0?b.polygonOffsetUnits:
0};THREE.NoShading=0;THREE.FlatShading=1;THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;THREE.VertexColors=2;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.MultiplyBlending=3;THREE.AdditiveAlphaBlending=4;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(){};THREE.LineBasicMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.linewidth=b.linewidth!==void 0?b.linewidth:1;this.linecap=b.linecap!==void 0?b.linecap:"round";this.linejoin=b.linejoin!==void 0?b.linejoin:"round";this.vertexColors=b.vertexColors?b.vertexColors:!1};THREE.LineBasicMaterial.prototype=new THREE.Material;
THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
THREE.MeshBasicMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.map=b.map!==void 0?b.map:null;this.lightMap=b.lightMap!==void 0?b.lightMap:null;this.envMap=b.envMap!==void 0?b.envMap:null;this.combine=b.combine!==void 0?b.combine:THREE.MultiplyOperation;this.reflectivity=b.reflectivity!==void 0?b.reflectivity:1;this.refractionRatio=b.refractionRatio!==void 0?b.refractionRatio:0.98;this.shading=b.shading!==
void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.wireframeLinecap=b.wireframeLinecap!==void 0?b.wireframeLinecap:"round";this.wireframeLinejoin=b.wireframeLinejoin!==void 0?b.wireframeLinejoin:"round";this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?b.morphTargets:!1};
THREE.MeshBasicMaterial.prototype=new THREE.Material;THREE.MeshBasicMaterial.prototype.constructor=THREE.MeshBasicMaterial;
THREE.MeshLambertMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.map=b.map!==void 0?b.map:null;this.lightMap=b.lightMap!==void 0?b.lightMap:null;this.envMap=b.envMap!==void 0?b.envMap:null;this.combine=b.combine!==void 0?b.combine:THREE.MultiplyOperation;this.reflectivity=b.reflectivity!==void 0?b.reflectivity:1;this.refractionRatio=b.refractionRatio!==void 0?b.refractionRatio:0.98;this.shading=b.shading!==
void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.wireframeLinecap=b.wireframeLinecap!==void 0?b.wireframeLinecap:"round";this.wireframeLinejoin=b.wireframeLinejoin!==void 0?b.wireframeLinejoin:"round";this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?b.morphTargets:!1};
THREE.MeshLambertMaterial.prototype=new THREE.Material;THREE.MeshLambertMaterial.prototype.constructor=THREE.MeshLambertMaterial;
THREE.MeshPhongMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.ambient=b.ambient!==void 0?new THREE.Color(b.ambient):new THREE.Color(328965);this.specular=b.specular!==void 0?new THREE.Color(b.specular):new THREE.Color(1118481);this.shininess=b.shininess!==void 0?b.shininess:30;this.map=b.map!==void 0?b.map:null;this.lightMap=b.lightMap!==void 0?b.lightMap:null;this.envMap=b.envMap!==void 0?b.envMap:null;
this.combine=b.combine!==void 0?b.combine:THREE.MultiplyOperation;this.reflectivity=b.reflectivity!==void 0?b.reflectivity:1;this.refractionRatio=b.refractionRatio!==void 0?b.refractionRatio:0.98;this.shading=b.shading!==void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.wireframeLinecap=b.wireframeLinecap!==void 0?b.wireframeLinecap:"round";this.wireframeLinejoin=b.wireframeLinejoin!==
void 0?b.wireframeLinejoin:"round";this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?b.morphTargets:!1};THREE.MeshPhongMaterial.prototype=new THREE.Material;THREE.MeshPhongMaterial.prototype.constructor=THREE.MeshPhongMaterial;
THREE.MeshDepthMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.shading=b.shading!==void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1};THREE.MeshDepthMaterial.prototype=new THREE.Material;THREE.MeshDepthMaterial.prototype.constructor=THREE.MeshDepthMaterial;
THREE.MeshNormalMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.shading=b.shading?b.shading:THREE.FlatShading;this.wireframe=b.wireframe?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth?b.wireframeLinewidth:1};THREE.MeshNormalMaterial.prototype=new THREE.Material;THREE.MeshNormalMaterial.prototype.constructor=THREE.MeshNormalMaterial;THREE.MeshFaceMaterial=function(){};
THREE.MeshShaderMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.fragmentShader=b.fragmentShader!==void 0?b.fragmentShader:"void main() {}";this.vertexShader=b.vertexShader!==void 0?b.vertexShader:"void main() {}";this.uniforms=b.uniforms!==void 0?b.uniforms:{};this.attributes=b.attributes;this.shading=b.shading!==void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.fog=
b.fog!==void 0?b.fog:!1;this.lights=b.lights!==void 0?b.lights:!1;this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?b.morphTargets:!1};THREE.MeshShaderMaterial.prototype=new THREE.Material;THREE.MeshShaderMaterial.prototype.constructor=THREE.MeshShaderMaterial;
THREE.ShadowVolumeDynamicMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.map=b.map!==void 0?b.map:null;this.lightMap=b.lightMap!==void 0?b.lightMap:null;this.envMap=b.envMap!==void 0?b.envMap:null;this.combine=b.combine!==void 0?b.combine:THREE.MultiplyOperation;this.reflectivity=b.reflectivity!==void 0?b.reflectivity:1;this.refractionRatio=b.refractionRatio!==void 0?b.refractionRatio:0.98;this.shading=b.shading!==
void 0?b.shading:THREE.SmoothShading;this.wireframe=b.wireframe!==void 0?b.wireframe:!1;this.wireframeLinewidth=b.wireframeLinewidth!==void 0?b.wireframeLinewidth:1;this.wireframeLinecap=b.wireframeLinecap!==void 0?b.wireframeLinecap:"round";this.wireframeLinejoin=b.wireframeLinejoin!==void 0?b.wireframeLinejoin:"round";this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1;this.skinning=b.skinning!==void 0?b.skinning:!1;this.morphTargets=b.morphTargets!==void 0?b.morphTargets:!1};
THREE.ShadowVolumeDynamicMaterial.prototype=new THREE.Material;THREE.ShadowVolumeDynamicMaterial.prototype.constructor=THREE.ShadowVolumeDynamicMaterial;
THREE.ParticleBasicMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.map=b.map!==void 0?b.map:null;this.size=b.size!==void 0?b.size:1;this.sizeAttenuation=b.sizeAttenuation!==void 0?b.sizeAttenuation:!0;this.vertexColors=b.vertexColors!==void 0?b.vertexColors:!1};THREE.ParticleBasicMaterial.prototype=new THREE.Material;THREE.ParticleBasicMaterial.prototype.constructor=THREE.ParticleBasicMaterial;
THREE.ParticleCanvasMaterial=function(b){THREE.Material.call(this,b);b=b||{};this.color=b.color!==void 0?new THREE.Color(b.color):new THREE.Color(16777215);this.program=b.program!==void 0?b.program:function(){}};THREE.ParticleCanvasMaterial.prototype=new THREE.Material;THREE.ParticleCanvasMaterial.prototype.constructor=THREE.ParticleCanvasMaterial;THREE.ParticleDOMMaterial=function(b){THREE.Material.call(this);this.domElement=b};
M
Mr.doob 已提交
106
THREE.Texture=function(b,c,e,f,g,k){this.image=b;this.mapping=c!==void 0?c:new THREE.UVMapping;this.wrapS=e!==void 0?e:THREE.ClampToEdgeWrapping;this.wrapT=f!==void 0?f:THREE.ClampToEdgeWrapping;this.magFilter=g!==void 0?g:THREE.LinearFilter;this.minFilter=k!==void 0?k:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.needsUpdate=!1};
107 108
THREE.Texture.prototype={clone:function(){return new THREE.Texture(this.image,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter)}};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;THREE.Particle=function(b){THREE.Object3D.call(this);this.materials=b instanceof Array?b:[b]};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;
M
Mr.doob 已提交
109
THREE.ParticleSystem=function(b,c){THREE.Object3D.call(this);this.geometry=b;this.materials=c instanceof Array?c:[c];this.sortParticles=!1};THREE.ParticleSystem.prototype=new THREE.Object3D;THREE.ParticleSystem.prototype.constructor=THREE.ParticleSystem;THREE.Line=function(b,c,e){THREE.Object3D.call(this);this.geometry=b;this.materials=c instanceof Array?c:[c];this.type=e!=void 0?e:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;
110
THREE.Line.prototype.constructor=THREE.Line;
M
Mr.doob 已提交
111 112
THREE.Mesh=function(b,c){THREE.Object3D.call(this);this.geometry=b;this.materials=c&&c.length?c:[c];this.overdraw=!1;if(this.geometry&&(this.geometry.boundingSphere||this.geometry.computeBoundingSphere(),this.boundRadius=b.boundingSphere.radius,this.geometry.morphTargets.length)){this.morphTargetBase=-1;this.morphTargetForcedOrder=[];this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var e=0;e<this.geometry.morphTargets.length;e++)this.morphTargetInfluences.push(0),this.morphTargetDictionary[this.geometry.morphTargets[e].name]=
e}};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.Mesh.prototype.supr=THREE.Object3D.prototype;THREE.Mesh.prototype.getMorphTargetIndexByName=function(b){if(this.morphTargetDictionary[b]!==void 0)return this.morphTargetDictionary[b];console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+b+" does not exist. Returning 0.");return 0};
113
THREE.Bone=function(b){THREE.Object3D.call(this);this.skin=b;this.skinMatrix=new THREE.Matrix4;this.hasNoneBoneChildren=!1};THREE.Bone.prototype=new THREE.Object3D;THREE.Bone.prototype.constructor=THREE.Bone;THREE.Bone.prototype.supr=THREE.Object3D.prototype;
M
Mr.doob 已提交
114 115
THREE.Bone.prototype.update=function(b,c,e){this.matrixAutoUpdate&&(c|=this.updateMatrix());if(c||this.matrixWorldNeedsUpdate)b?this.skinMatrix.multiply(b,this.matrix):this.skinMatrix.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,c=!0;var f,g=this.children.length;if(this.hasNoneBoneChildren){this.matrixWorld.multiply(this.skin.matrixWorld,this.skinMatrix);for(f=0;f<g;f++)b=this.children[f],b instanceof THREE.Bone?b.update(this.skinMatrix,c,e):b.update(this.matrixWorld,!0,e)}else for(f=0;f<g;f++)this.children[f].update(this.skinMatrix,
c,e)};THREE.Bone.prototype.addChild=function(b){if(this.children.indexOf(b)===-1&&(b.parent!==void 0&&b.parent.removeChild(b),b.parent=this,this.children.push(b),!(b instanceof THREE.Bone)))this.hasNoneBoneChildren=!0};
M
Mr.doob 已提交
116
THREE.SkinnedMesh=function(b,c){THREE.Mesh.call(this,b,c);this.identityMatrix=new THREE.Matrix4;this.bones=[];this.boneMatrices=[];var e,f,g,k,h,m;if(this.geometry.bones!==void 0){for(e=0;e<this.geometry.bones.length;e++)g=this.geometry.bones[e],k=g.pos,h=g.rotq,m=g.scl,f=this.addBone(),f.name=g.name,f.position.set(k[0],k[1],k[2]),f.quaternion.set(h[0],h[1],h[2],h[3]),f.useQuaternion=!0,m!==void 0?f.scale.set(m[0],m[1],m[2]):f.scale.set(1,1,1);for(e=0;e<this.bones.length;e++)g=this.geometry.bones[e],
M
Mr.doob 已提交
117 118
f=this.bones[e],g.parent===-1?this.addChild(f):this.bones[g.parent].addChild(f);this.boneMatrices=new Float32Array(16*this.bones.length);this.pose()}};THREE.SkinnedMesh.prototype=new THREE.Mesh;THREE.SkinnedMesh.prototype.constructor=THREE.SkinnedMesh;
THREE.SkinnedMesh.prototype.update=function(b,c,e){if(this.visible){this.matrixAutoUpdate&&(c|=this.updateMatrix());if(c||this.matrixWorldNeedsUpdate)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,c=!0;var f,g=this.children.length;for(f=0;f<g;f++)b=this.children[f],b instanceof THREE.Bone?b.update(this.identityMatrix,!1,e):b.update(this.matrixWorld,c,e);e=this.bones.length;ba=this.bones;bm=this.boneMatrices;for(c=0;c<e;c++)ba[c].skinMatrix.flattenToArrayOffset(bm,
119
c*16)}};THREE.SkinnedMesh.prototype.addBone=function(b){b===void 0&&(b=new THREE.Bone(this));this.bones.push(b);return b};
M
Mr.doob 已提交
120 121
THREE.SkinnedMesh.prototype.pose=function(){this.update(void 0,!0);for(var b,c=[],e=0;e<this.bones.length;e++)b=this.bones[e],c.push(THREE.Matrix4.makeInvert(b.skinMatrix)),b.skinMatrix.flattenToArrayOffset(this.boneMatrices,e*16);if(this.geometry.skinVerticesA===void 0){this.geometry.skinVerticesA=[];this.geometry.skinVerticesB=[];var f;for(b=0;b<this.geometry.skinIndices.length;b++){var e=this.geometry.vertices[b].position,g=this.geometry.skinIndices[b].x,k=this.geometry.skinIndices[b].y;f=new THREE.Vector3(e.x,
e.y,e.z);this.geometry.skinVerticesA.push(c[g].multiplyVector3(f));f=new THREE.Vector3(e.x,e.y,e.z);this.geometry.skinVerticesB.push(c[k].multiplyVector3(f));this.geometry.skinWeights[b].x+this.geometry.skinWeights[b].y!==1&&(e=(1-(this.geometry.skinWeights[b].x+this.geometry.skinWeights[b].y))*0.5,this.geometry.skinWeights[b].x+=e,this.geometry.skinWeights[b].y+=e)}}};THREE.Ribbon=function(b,c){THREE.Object3D.call(this);this.geometry=b;this.materials=c instanceof Array?c:[c]};
122
THREE.Ribbon.prototype=new THREE.Object3D;THREE.Ribbon.prototype.constructor=THREE.Ribbon;THREE.LOD=function(){THREE.Object3D.call(this);this.LODs=[]};THREE.LOD.prototype=new THREE.Object3D;THREE.LOD.prototype.constructor=THREE.LOD;THREE.LOD.prototype.supr=THREE.Object3D.prototype;THREE.LOD.prototype.add=function(b,c){c===void 0&&(c=0);for(var c=Math.abs(c),e=0;e<this.LODs.length;e++)if(c<this.LODs[e].visibleAtDistance)break;this.LODs.splice(e,0,{visibleAtDistance:c,object3D:b});this.addChild(b)};
M
Mr.doob 已提交
123 124
THREE.LOD.prototype.update=function(b,c,e){this.matrixAutoUpdate&&(c|=this.updateMatrix());if(c||this.matrixWorldNeedsUpdate)b?this.matrixWorld.multiply(b,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,c=!0;if(this.LODs.length>1){b=e.matrixWorldInverse;b=-(b.n31*this.position.x+b.n32*this.position.y+b.n33*this.position.z+b.n34);this.LODs[0].object3D.visible=!0;for(var f=1;f<this.LODs.length;f++)if(b>=this.LODs[f].visibleAtDistance)this.LODs[f-1].object3D.visible=!1,
this.LODs[f].object3D.visible=!0;else break;for(;f<this.LODs.length;f++)this.LODs[f].object3D.visible=!1}for(b=0;b<this.children.length;b++)this.children[b].update(this.matrixWorld,c,e)};THREE.ShadowVolume=function(b,c){b instanceof THREE.Mesh?(THREE.Mesh.call(this,b.geometry,c?[new THREE.ShadowVolumeDynamicMaterial]:[new THREE.ShadowVolumeDynamicMaterial]),b.addChild(this)):THREE.Mesh.call(this,b,c?[new THREE.ShadowVolumeDynamicMaterial]:[new THREE.ShadowVolumeDynamicMaterial]);this.calculateShadowVolumeGeometry()};
125
THREE.ShadowVolume.prototype=new THREE.Mesh;THREE.ShadowVolume.prototype.constructor=THREE.ShadowVolume;THREE.ShadowVolume.prototype.supr=THREE.Mesh.prototype;
126 127 128 129 130 131 132
THREE.ShadowVolume.prototype.calculateShadowVolumeGeometry=function(){if(this.geometry.edges&&this.geometry.edges.length){var b,c,e,f,g,k,h,m,n,p,o,t,v,u,w=new THREE.Geometry;w.vertices=this.geometry.vertices;f=w.faces=this.geometry.faces;var B=w.egdes=this.geometry.edges,A=w.edgeFaces=[];g=0;var y=[];b=0;for(c=f.length;b<c;b++)if(e=f[b],y.push(g),g+=e instanceof THREE.Face3?3:4,e.vertexNormals[0]=e.normal,e.vertexNormals[1]=e.normal,e.vertexNormals[2]=e.normal,e instanceof THREE.Face4)e.vertexNormals[3]=
e.normal;b=0;for(c=B.length;b<c;b++)m=B[b],e=m.faces[0],f=m.faces[1],g=m.faceIndices[0],k=m.faceIndices[1],h=m.vertexIndices[0],m=m.vertexIndices[1],e.a===h?(n="a",o=y[g]+0):e.b===h?(n="b",o=y[g]+1):e.c===h?(n="c",o=y[g]+2):e.d===h&&(n="d",o=y[g]+3),e.a===m?(n+="a",t=y[g]+0):e.b===m?(n+="b",t=y[g]+1):e.c===m?(n+="c",t=y[g]+2):e.d===m&&(n+="d",t=y[g]+3),f.a===h?(p="a",v=y[k]+0):f.b===h?(p="b",v=y[k]+1):f.c===h?(p="c",v=y[k]+2):f.d===h&&(p="d",v=y[k]+3),f.a===m?(p+="a",u=y[k]+0):f.b===m?(p+="b",u=y[k]+
1):f.c===m?(p+="c",u=y[k]+2):f.d===m&&(p+="d",u=y[k]+3),n==="ac"||n==="ad"||n==="ca"||n==="da"?o>t&&(e=o,o=t,t=e):o<t&&(e=o,o=t,t=e),p==="ac"||p==="ad"||p==="ca"||p==="da"?v>u&&(e=v,v=u,u=e):v<u&&(e=v,v=u,u=e),e=new THREE.Face4(o,t,v,u),e.normal.set(1,0,0),A.push(e);this.geometry=w}else this.calculateShadowVolumeGeometryWithoutEdgeInfo(this.geometry)};
THREE.ShadowVolume.prototype.calculateShadowVolumeGeometryWithoutEdgeInfo=function(b){this.geometry=new THREE.Geometry;this.geometry.boundingSphere=b.boundingSphere;this.geometry.edgeFaces=[];var c=this.geometry.vertices,e=this.geometry.faces,f=this.geometry.edgeFaces,g=b.faces,b=b.vertices,k=g.length,h,m,n,p,o,t=["a","b","c","d"];for(n=0;n<k;n++){m=c.length;h=g[n];h instanceof THREE.Face4?(p=4,m=new THREE.Face4(m,m+1,m+2,m+3)):(p=3,m=new THREE.Face3(m,m+1,m+2));m.normal.copy(h.normal);e.push(m);
for(m=0;m<p;m++)o=b[h[t[m]]],c.push(new THREE.Vertex(o.position.clone()))}for(k=0;k<g.length-1;k++){b=e[k];for(h=k+1;h<g.length;h++)m=e[h],m=this.facesShareEdge(c,b,m),m!==void 0&&(m=new THREE.Face4(m.indices[0],m.indices[3],m.indices[2],m.indices[1]),m.normal.set(1,0,0),f.push(m))}};
THREE.ShadowVolume.prototype.facesShareEdge=function(b,c,e){var f,g,k,h,m,n,p,o,t,v,u,w,B,A=0,y=["a","b","c","d"];f=c instanceof THREE.Face4?4:3;g=e instanceof THREE.Face4?4:3;for(w=0;w<f;w++){k=c[y[w]];m=b[k];for(B=0;B<g;B++)if(h=e[y[B]],n=b[h],Math.abs(m.position.x-n.position.x)<1.0E-4&&Math.abs(m.position.y-n.position.y)<1.0E-4&&Math.abs(m.position.z-n.position.z)<1.0E-4&&(A++,A===1&&(p=m,o=n,t=k,v=h,u=y[w]),A===2))return u+=y[w],u==="ad"||u==="ac"?{faces:[c,e],vertices:[p,o,n,m],indices:[t,v,
h,k],vertexTypes:[1,2,2,1],extrudable:!0}:{faces:[c,e],vertices:[p,m,n,o],indices:[t,k,h,v],vertexTypes:[1,1,2,2],extrudable:!0}}};
133 134 135 136
THREE.Sprite=function(b){THREE.Object3D.call(this);if(b.material!==void 0)this.material=b.material,this.map=void 0,this.blending=material.blending;else if(b.map!==void 0)this.map=b.map instanceof THREE.Texture?b.map:THREE.ImageUtils.loadTexture(b.map),this.material=void 0,this.blending=b.blending!==void 0?b.blending:THREE.NormalBlending;this.useScreenCoordinates=b.useScreenCoordinates!==void 0?b.useScreenCoordinates:!0;this.mergeWith3D=b.mergeWith3D!==void 0?b.mergeWith3D:!this.useScreenCoordinates;
this.affectedByDistance=b.affectedByDistance!==void 0?b.affectedByDistance:!this.useScreenCoordinates;this.scaleByViewport=b.scaleByViewport!==void 0?b.scaleByViewport:!this.affectedByDistance;this.alignment=b.alignment instanceof THREE.Vector2?b.alignment:THREE.SpriteAlignment.center;this.rotation3d=this.rotation;this.rotation=0;this.opacity=1;this.uvOffset=new THREE.Vector2(0,0);this.uvScale=new THREE.Vector2(1,1)};THREE.Sprite.prototype=new THREE.Object3D;THREE.Sprite.prototype.constructor=THREE.Sprite;
THREE.Sprite.prototype.supr=THREE.Object3D.prototype;THREE.Sprite.prototype.updateMatrix=function(){this.matrix.setPosition(this.position);this.rotation3d.set(0,0,this.rotation);this.matrix.setRotationFromEuler(this.rotation3d);if(this.scale.x!==1||this.scale.y!==1)this.matrix.scale(this.scale),this.boundRadiusScale=Math.max(this.scale.x,this.scale.y);this.matrixWorldNeedsUpdate=!0};THREE.SpriteAlignment={};THREE.SpriteAlignment.topLeft=new THREE.Vector2(1,-1);
THREE.SpriteAlignment.topCenter=new THREE.Vector2(0,-1);THREE.SpriteAlignment.topRight=new THREE.Vector2(-1,-1);THREE.SpriteAlignment.centerLeft=new THREE.Vector2(1,0);THREE.SpriteAlignment.center=new THREE.Vector2(0,0);THREE.SpriteAlignment.centerRight=new THREE.Vector2(-1,0);THREE.SpriteAlignment.bottomLeft=new THREE.Vector2(1,1);THREE.SpriteAlignment.bottomCenter=new THREE.Vector2(0,1);THREE.SpriteAlignment.bottomRight=new THREE.Vector2(-1,1);
137 138 139 140
THREE.Scene=function(){THREE.Object3D.call(this);this.matrixAutoUpdate=!1;this.collisions=this.overrideMaterial=this.fog=null;this.objects=[];this.lights=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;THREE.Scene.prototype.supr=THREE.Object3D.prototype;THREE.Scene.prototype.addChild=function(b){this.supr.addChild.call(this,b);this.addChildRecurse(b)};
THREE.Scene.prototype.addChildRecurse=function(b){if(b instanceof THREE.Light)this.lights.indexOf(b)===-1&&this.lights.push(b);else if(!(b instanceof THREE.Camera||b instanceof THREE.Bone)&&this.objects.indexOf(b)===-1)this.objects.push(b),this.__objectsAdded.push(b);for(var c=0;c<b.children.length;c++)this.addChildRecurse(b.children[c])};THREE.Scene.prototype.removeChild=function(b){this.supr.removeChild.call(this,b);this.removeChildRecurse(b)};
THREE.Scene.prototype.removeChildRecurse=function(b){if(b instanceof THREE.Light){var c=this.lights.indexOf(b);c!==-1&&this.lights.splice(c,1)}else b instanceof THREE.Camera||(c=this.objects.indexOf(b),c!==-1&&(this.objects.splice(c,1),this.__objectsRemoved.push(b)));for(c=0;c<b.children.length;c++)this.removeChildRecurse(b.children[c])};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(b,c,e){this.color=new THREE.Color(b);this.near=c||1;this.far=e||1E3};THREE.FogExp2=function(b,c){this.color=new THREE.Color(b);this.density=c!==void 0?c:2.5E-4};
141
THREE.Projector=function(){function b(){var b=n[m]=n[m]||new THREE.RenderableVertex;m++;return b}function c(b,e){return e.z-b.z}function e(b,e){var c=0,f=1,g=b.z+b.w,h=e.z+e.w,k=-b.z+b.w,m=-e.z+e.w;return g>=0&&h>=0&&k>=0&&m>=0?!0:g<0&&h<0||k<0&&m<0?!1:(g<0?c=Math.max(c,g/(g-h)):h<0&&(f=Math.min(f,g/(g-h))),k<0?c=Math.max(c,k/(k-m)):m<0&&(f=Math.min(f,k/(k-m))),f<c?!1:(b.lerpSelf(e,c),e.lerpSelf(b,1-f),!0))}var f,g,k=[],h,m,n=[],p,o,t=[],v,u=[],w,B,A=[],y,G,z=[],C=new THREE.Vector4,H=new THREE.Vector4,
M
Mr.doob 已提交
142 143
D=new THREE.Matrix4,Q=new THREE.Matrix4,J=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],F=new THREE.Vector4,I=new THREE.Vector4;this.projectVector=function(b,e){D.multiply(e.projectionMatrix,e.matrixWorldInverse);D.multiplyVector3(b);return b};this.unprojectVector=function(b,e){D.multiply(e.matrixWorld,THREE.Matrix4.makeInvert(e.projectionMatrix));D.multiplyVector3(b);return b};this.projectObjects=function(b,e,h){var e=[],j,m,n;g=0;m=
b.objects;b=0;for(j=m.length;b<j;b++){n=m[b];var o;if(!(o=!n.visible))if(o=n instanceof THREE.Mesh){a:{o=void 0;for(var p=n.matrixWorld,t=-n.geometry.boundingSphere.radius*Math.max(n.scale.x,Math.max(n.scale.y,n.scale.z)),u=0;u<6;u++)if(o=J[u].x*p.n14+J[u].y*p.n24+J[u].z*p.n34+J[u].w,o<=t){o=!1;break a}o=!0}o=!o}if(!o)o=k[g]=k[g]||new THREE.RenderableObject,g++,f=o,C.copy(n.position),D.multiplyVector3(C),f.object=n,f.z=C.z,e.push(f)}h&&e.sort(c);return e};this.projectScene=function(f,g,k){var j=[],
144 145
C=g.near,T=g.far,Z,N,da,X,aa,ia,ha,na,ja,L,fa,V,U,$,Y,ka,la;G=B=v=o=0;g.matrixAutoUpdate&&g.update(void 0,!0);f.update(void 0,!1,g);D.multiply(g.projectionMatrix,g.matrixWorldInverse);J[0].set(D.n41-D.n11,D.n42-D.n12,D.n43-D.n13,D.n44-D.n14);J[1].set(D.n41+D.n11,D.n42+D.n12,D.n43+D.n13,D.n44+D.n14);J[2].set(D.n41+D.n21,D.n42+D.n22,D.n43+D.n23,D.n44+D.n24);J[3].set(D.n41-D.n21,D.n42-D.n22,D.n43-D.n23,D.n44-D.n24);J[4].set(D.n41-D.n31,D.n42-D.n32,D.n43-D.n33,D.n44-D.n34);J[5].set(D.n41+D.n31,D.n42+
D.n32,D.n43+D.n33,D.n44+D.n34);for(Z=0;Z<6;Z++)ja=J[Z],ja.divideScalar(Math.sqrt(ja.x*ja.x+ja.y*ja.y+ja.z*ja.z));ja=this.projectObjects(f,g,!0);f=0;for(Z=ja.length;f<Z;f++)if(L=ja[f].object,L.visible)if(fa=L.matrixWorld,V=L.matrixRotationWorld,U=L.materials,$=L.overdraw,m=0,L instanceof THREE.Mesh){Y=L.geometry;X=Y.vertices;ka=Y.faces;Y=Y.faceVertexUvs;N=0;for(da=X.length;N<da;N++)h=b(),h.positionWorld.copy(X[N].position),fa.multiplyVector3(h.positionWorld),h.positionScreen.copy(h.positionWorld),
M
Mr.doob 已提交
146
D.multiplyVector4(h.positionScreen),h.positionScreen.x/=h.positionScreen.w,h.positionScreen.y/=h.positionScreen.w,h.visible=h.positionScreen.z>C&&h.positionScreen.z<T;X=0;for(N=ka.length;X<N;X++){da=ka[X];if(da instanceof THREE.Face3)if(aa=n[da.a],ia=n[da.b],ha=n[da.c],aa.visible&&ia.visible&&ha.visible&&(L.doubleSided||L.flipSided!=(ha.positionScreen.x-aa.positionScreen.x)*(ia.positionScreen.y-aa.positionScreen.y)-(ha.positionScreen.y-aa.positionScreen.y)*(ia.positionScreen.x-aa.positionScreen.x)<
147 148 149
0))na=t[o]=t[o]||new THREE.RenderableFace3,o++,p=na,p.v1.copy(aa),p.v2.copy(ia),p.v3.copy(ha);else continue;else if(da instanceof THREE.Face4)if(aa=n[da.a],ia=n[da.b],ha=n[da.c],na=n[da.d],aa.visible&&ia.visible&&ha.visible&&na.visible&&(L.doubleSided||L.flipSided!=((na.positionScreen.x-aa.positionScreen.x)*(ia.positionScreen.y-aa.positionScreen.y)-(na.positionScreen.y-aa.positionScreen.y)*(ia.positionScreen.x-aa.positionScreen.x)<0||(ia.positionScreen.x-ha.positionScreen.x)*(na.positionScreen.y-
ha.positionScreen.y)-(ia.positionScreen.y-ha.positionScreen.y)*(na.positionScreen.x-ha.positionScreen.x)<0)))la=u[v]=u[v]||new THREE.RenderableFace4,v++,p=la,p.v1.copy(aa),p.v2.copy(ia),p.v3.copy(ha),p.v4.copy(na);else continue;p.normalWorld.copy(da.normal);V.multiplyVector3(p.normalWorld);p.centroidWorld.copy(da.centroid);fa.multiplyVector3(p.centroidWorld);p.centroidScreen.copy(p.centroidWorld);D.multiplyVector3(p.centroidScreen);ha=da.vertexNormals;aa=0;for(ia=ha.length;aa<ia;aa++)na=p.vertexNormalsWorld[aa],
na.copy(ha[aa]),V.multiplyVector3(na);aa=0;for(ia=Y.length;aa<ia;aa++)if(la=Y[aa][X]){ha=0;for(na=la.length;ha<na;ha++)p.uvs[aa][ha]=la[ha]}p.meshMaterials=U;p.faceMaterials=da.materials;p.overdraw=$;p.z=p.centroidScreen.z;j.push(p)}}else if(L instanceof THREE.Line){Q.multiply(D,fa);X=L.geometry.vertices;aa=b();aa.positionScreen.copy(X[0].position);Q.multiplyVector4(aa.positionScreen);N=1;for(da=X.length;N<da;N++)if(aa=b(),aa.positionScreen.copy(X[N].position),Q.multiplyVector4(aa.positionScreen),
M
Mr.doob 已提交
150
ia=n[m-2],F.copy(aa.positionScreen),I.copy(ia.positionScreen),e(F,I))F.multiplyScalar(1/F.w),I.multiplyScalar(1/I.w),fa=A[B]=A[B]||new THREE.RenderableLine,B++,w=fa,w.v1.positionScreen.copy(F),w.v2.positionScreen.copy(I),w.z=Math.max(F.z,I.z),w.materials=L.materials,j.push(w)}else if(L instanceof THREE.Particle&&(H.set(L.matrixWorld.n14,L.matrixWorld.n24,L.matrixWorld.n34,1),D.multiplyVector4(H),H.z/=H.w,H.z>0&&H.z<1))fa=z[G]=z[G]||new THREE.RenderableParticle,G++,y=fa,y.x=H.x/H.w,y.y=H.y/H.w,y.z=
M
Mr.doob 已提交
151
H.z,y.rotation=L.rotation.z,y.scale.x=L.scale.x*Math.abs(y.x-(H.x+g.projectionMatrix.n11)/(H.w+g.projectionMatrix.n14)),y.scale.y=L.scale.y*Math.abs(y.y-(H.y+g.projectionMatrix.n22)/(H.w+g.projectionMatrix.n24)),y.materials=L.materials,j.push(y);k&&j.sort(c);return j}};
152
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var b=null,c=new THREE.Projector,e,f,g,k;this.domElement=document.createElement("div");this.setSize=function(b,c){e=b;f=c;g=e/2;k=f/2};this.render=function(e,f){var n,p,o,t,v,u,w,B;b=c.projectScene(e,f);n=0;for(p=b.length;n<p;n++)if(v=b[n],v instanceof THREE.RenderableParticle){w=v.x*g+g;B=v.y*k+k;o=0;for(t=v.material.length;o<t;o++)if(u=v.material[o],u instanceof THREE.ParticleDOMMaterial)u=u.domElement,u.style.left=w+"px",u.style.top=B+"px"}}};
M
Mr.doob 已提交
153
THREE.CanvasRenderer=function(b){function c(b){if(y!=b)w.globalAlpha=y=b}function e(b){if(G!=b){switch(b){case THREE.NormalBlending:w.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:w.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:w.globalCompositeOperation="darker"}G=b}}function f(b){if(z!=b.hex)z=b.hex,w.strokeStyle="#"+k(z.toString(16))}function g(b){if(C!=b.hex)C=b.hex,w.fillStyle="#"+k(C.toString(16))}function k(b){for(;b.length<6;)b="0"+b;return b}
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
var h=this,m=null,n=new THREE.Projector,b=b||{},p=b.canvas!==void 0?b.canvas:document.createElement("canvas"),o,t,v,u,w=p.getContext("2d"),B=new THREE.Color(0),A=0,y=1,G=0,z=null,C=null,H=null,D=null,Q=null,J,F,I,S,K=new THREE.RenderableVertex,ea=new THREE.RenderableVertex,j,ca,T,Z,N,da,X,aa,ia,ha,na,ja,L=new THREE.Color(0),fa=new THREE.Color(0),V=new THREE.Color(0),U=new THREE.Color(0),$=new THREE.Color(0),Y,ka,la,ga,Da,ua,Aa,xa,ta,ya,va=new THREE.Rectangle,qa=new THREE.Rectangle,R=new THREE.Rectangle,
O=!1,oa=new THREE.Color,P=new THREE.Color,Ba=new THREE.Color,W=new THREE.Color,pa=new THREE.Vector3,Pa,Qa,Wa,wa,Ra,Sa,b=16;Pa=document.createElement("canvas");Pa.width=Pa.height=2;Qa=Pa.getContext("2d");Qa.fillStyle="rgba(0,0,0,1)";Qa.fillRect(0,0,2,2);Wa=Qa.getImageData(0,0,2,2);wa=Wa.data;Ra=document.createElement("canvas");Ra.width=Ra.height=b;Sa=Ra.getContext("2d");Sa.translate(-b/2,-b/2);Sa.scale(b,b);b--;this.domElement=p;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,
faces:0};this.setSize=function(b,e){o=b;t=e;v=o/2;u=t/2;p.width=o;p.height=t;va.set(-v,-u,v,u);y=1;G=0;Q=D=H=C=z=null};this.setClearColor=function(b,e){B=b;A=e};this.setClearColorHex=function(b,e){B.setHex(b);A=e};this.clear=function(){w.setTransform(1,0,0,-1,v,u);if(!qa.isEmpty())qa.inflate(1),qa.minSelf(va),B.hex==0&&A==0?w.clearRect(qa.getX(),qa.getY(),qa.getWidth(),qa.getHeight()):(e(THREE.NormalBlending),c(1),w.fillStyle="rgba("+Math.floor(B.r*255)+","+Math.floor(B.g*255)+","+Math.floor(B.b*
255)+","+A+")",w.fillRect(qa.getX(),qa.getY(),qa.getWidth(),qa.getHeight())),qa.empty()};this.render=function(b,k){function o(b){var e,c,f,j=b.lights;P.setRGB(0,0,0);Ba.setRGB(0,0,0);W.setRGB(0,0,0);b=0;for(e=j.length;b<e;b++)c=j[b],f=c.color,c instanceof THREE.AmbientLight?(P.r+=f.r,P.g+=f.g,P.b+=f.b):c instanceof THREE.DirectionalLight?(Ba.r+=f.r,Ba.g+=f.g,Ba.b+=f.b):c instanceof THREE.PointLight&&(W.r+=f.r,W.g+=f.g,W.b+=f.b)}function p(b,e,c,f){var j,g,h,k,m=b.lights,b=0;for(j=m.length;b<j;b++)g=
m[b],h=g.color,g instanceof THREE.DirectionalLight?(k=c.dot(g.position),k<=0||(k*=g.intensity,f.r+=h.r*k,f.g+=h.g*k,f.b+=h.b*k)):g instanceof THREE.PointLight&&(k=c.dot(pa.sub(g.position,e).normalize()),k<=0||(k*=g.distance==0?1:1-Math.min(e.distanceTo(g.position)/g.distance,1),k!=0&&(k*=g.intensity,f.r+=h.r*k,f.g+=h.g*k,f.b+=h.b*k)))}function t(b,j,h){c(h.opacity);e(h.blending);var k,m,n,o,p,W;if(h instanceof THREE.ParticleBasicMaterial){if(h.map)o=h.map.image,p=o.width>>1,W=o.height>>1,h=j.scale.x*
v,n=j.scale.y*u,k=h*p,m=n*W,R.set(b.x-k,b.y-m,b.x+k,b.y+m),va.instersects(R)&&(w.save(),w.translate(b.x,b.y),w.rotate(-j.rotation),w.scale(h,-n),w.translate(-p,-W),w.drawImage(o,0,0),w.restore())}else h instanceof THREE.ParticleCanvasMaterial&&(k=j.scale.x*v,m=j.scale.y*u,R.set(b.x-k,b.y-m,b.x+k,b.y+m),va.instersects(R)&&(f(h.color),g(h.color),w.save(),w.translate(b.x,b.y),w.rotate(-j.rotation),w.scale(k,m),h.program(w),w.restore()))}function y(b,j,g,h){c(h.opacity);e(h.blending);w.beginPath();w.moveTo(b.positionScreen.x,
b.positionScreen.y);w.lineTo(j.positionScreen.x,j.positionScreen.y);w.closePath();if(h instanceof THREE.LineBasicMaterial){b=h.linewidth;if(H!=b)w.lineWidth=H=b;b=h.linecap;if(D!=b)w.lineCap=D=b;b=h.linejoin;if(Q!=b)w.lineJoin=Q=b;f(h.color);w.stroke();R.inflate(h.linewidth*2)}}function A(b,f,g,m,n,o,t,W,u){h.data.vertices+=3;h.data.faces++;c(W.opacity);e(W.blending);j=b.positionScreen.x;ca=b.positionScreen.y;T=f.positionScreen.x;Z=f.positionScreen.y;N=g.positionScreen.x;da=g.positionScreen.y;z(j,
ca,T,Z,N,da);if(W instanceof THREE.MeshBasicMaterial)if(W.map)W.map.mapping instanceof THREE.UVMapping&&(ga=t.uvs[0],Ea(j,ca,T,Z,N,da,W.map.image,ga[m].u,ga[m].v,ga[n].u,ga[n].v,ga[o].u,ga[o].v));else if(W.envMap){if(W.envMap.mapping instanceof THREE.SphericalReflectionMapping)b=k.matrixWorldInverse,pa.copy(t.vertexNormalsWorld[0]),Da=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+0.5,ua=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,pa.copy(t.vertexNormalsWorld[1]),Aa=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+
0.5,xa=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,pa.copy(t.vertexNormalsWorld[2]),ta=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+0.5,ya=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,Ea(j,ca,T,Z,N,da,W.envMap.image,Da,ua,Aa,xa,ta,ya)}else W.wireframe?C(W.color,W.wireframeLinewidth,W.wireframeLinecap,W.wireframeLinejoin):Ga(W.color);else if(W instanceof THREE.MeshLambertMaterial)W.map&&!W.wireframe&&(W.map.mapping instanceof THREE.UVMapping&&(ga=t.uvs[0],Ea(j,ca,T,Z,N,da,W.map.image,ga[m].u,ga[m].v,ga[n].u,
ga[n].v,ga[o].u,ga[o].v)),e(THREE.SubtractiveBlending)),O?!W.wireframe&&W.shading==THREE.SmoothShading&&t.vertexNormalsWorld.length==3?(fa.r=V.r=U.r=P.r,fa.g=V.g=U.g=P.g,fa.b=V.b=U.b=P.b,p(u,t.v1.positionWorld,t.vertexNormalsWorld[0],fa),p(u,t.v2.positionWorld,t.vertexNormalsWorld[1],V),p(u,t.v3.positionWorld,t.vertexNormalsWorld[2],U),$.r=(V.r+U.r)*0.5,$.g=(V.g+U.g)*0.5,$.b=(V.b+U.b)*0.5,la=Ta(fa,V,U,$),Ea(j,ca,T,Z,N,da,la,0,0,1,0,0,1)):(oa.r=P.r,oa.g=P.g,oa.b=P.b,p(u,t.centroidWorld,t.normalWorld,
oa),L.r=Math.max(0,Math.min(W.color.r*oa.r,1)),L.g=Math.max(0,Math.min(W.color.g*oa.g,1)),L.b=Math.max(0,Math.min(W.color.b*oa.b,1)),L.updateHex(),W.wireframe?C(L,W.wireframeLinewidth,W.wireframeLinecap,W.wireframeLinejoin):Ga(L)):W.wireframe?C(W.color,W.wireframeLinewidth,W.wireframeLinecap,W.wireframeLinejoin):Ga(W.color);else if(W instanceof THREE.MeshDepthMaterial)Y=k.near,ka=k.far,fa.r=fa.g=fa.b=1-Ja(b.positionScreen.z,Y,ka),V.r=V.g=V.b=1-Ja(f.positionScreen.z,Y,ka),U.r=U.g=U.b=1-Ja(g.positionScreen.z,
Y,ka),$.r=(V.r+U.r)*0.5,$.g=(V.g+U.g)*0.5,$.b=(V.b+U.b)*0.5,la=Ta(fa,V,U,$),Ea(j,ca,T,Z,N,da,la,0,0,1,0,0,1);else if(W instanceof THREE.MeshNormalMaterial)L.r=Na(t.normalWorld.x),L.g=Na(t.normalWorld.y),L.b=Na(t.normalWorld.z),L.updateHex(),W.wireframe?C(L,W.wireframeLinewidth,W.wireframeLinecap,W.wireframeLinejoin):Ga(L)}function B(b,f,g,m,n,o,W,t,u){h.data.vertices+=4;h.data.faces++;c(t.opacity);e(t.blending);if(t.map||t.envMap)A(b,f,m,0,1,3,W,t,u),A(n,g,o,1,2,3,W,t,u);else if(j=b.positionScreen.x,
ca=b.positionScreen.y,T=f.positionScreen.x,Z=f.positionScreen.y,N=g.positionScreen.x,da=g.positionScreen.y,X=m.positionScreen.x,aa=m.positionScreen.y,ia=n.positionScreen.x,ha=n.positionScreen.y,na=o.positionScreen.x,ja=o.positionScreen.y,t instanceof THREE.MeshBasicMaterial)G(j,ca,T,Z,N,da,X,aa),t.wireframe?C(t.color,t.wireframeLinewidth,t.wireframeLinecap,t.wireframeLinejoin):Ga(t.color);else if(t instanceof THREE.MeshLambertMaterial)O?!t.wireframe&&t.shading==THREE.SmoothShading&&W.vertexNormalsWorld.length==
4?(fa.r=V.r=U.r=$.r=P.r,fa.g=V.g=U.g=$.g=P.g,fa.b=V.b=U.b=$.b=P.b,p(u,W.v1.positionWorld,W.vertexNormalsWorld[0],fa),p(u,W.v2.positionWorld,W.vertexNormalsWorld[1],V),p(u,W.v4.positionWorld,W.vertexNormalsWorld[3],U),p(u,W.v3.positionWorld,W.vertexNormalsWorld[2],$),la=Ta(fa,V,U,$),z(j,ca,T,Z,X,aa),Ea(j,ca,T,Z,X,aa,la,0,0,1,0,0,1),z(ia,ha,N,da,na,ja),Ea(ia,ha,N,da,na,ja,la,1,0,1,1,0,1)):(oa.r=P.r,oa.g=P.g,oa.b=P.b,p(u,W.centroidWorld,W.normalWorld,oa),L.r=Math.max(0,Math.min(t.color.r*oa.r,1)),L.g=
Math.max(0,Math.min(t.color.g*oa.g,1)),L.b=Math.max(0,Math.min(t.color.b*oa.b,1)),L.updateHex(),G(j,ca,T,Z,N,da,X,aa),t.wireframe?C(L,t.wireframeLinewidth,t.wireframeLinecap,t.wireframeLinejoin):Ga(L)):(G(j,ca,T,Z,N,da,X,aa),t.wireframe?C(t.color,t.wireframeLinewidth,t.wireframeLinecap,t.wireframeLinejoin):Ga(t.color));else if(t instanceof THREE.MeshNormalMaterial)L.r=Na(W.normalWorld.x),L.g=Na(W.normalWorld.y),L.b=Na(W.normalWorld.z),L.updateHex(),G(j,ca,T,Z,N,da,X,aa),t.wireframe?C(L,t.wireframeLinewidth,
t.wireframeLinecap,t.wireframeLinejoin):Ga(L);else if(t instanceof THREE.MeshDepthMaterial)Y=k.near,ka=k.far,fa.r=fa.g=fa.b=1-Ja(b.positionScreen.z,Y,ka),V.r=V.g=V.b=1-Ja(f.positionScreen.z,Y,ka),U.r=U.g=U.b=1-Ja(m.positionScreen.z,Y,ka),$.r=$.g=$.b=1-Ja(g.positionScreen.z,Y,ka),la=Ta(fa,V,U,$),z(j,ca,T,Z,X,aa),Ea(j,ca,T,Z,X,aa,la,0,0,1,0,0,1),z(ia,ha,N,da,na,ja),Ea(ia,ha,N,da,na,ja,la,1,0,1,1,0,1)}function z(b,e,c,f,j,g){w.beginPath();w.moveTo(b,e);w.lineTo(c,f);w.lineTo(j,g);w.lineTo(b,e);w.closePath()}
function G(b,e,c,f,j,g,h,k){w.beginPath();w.moveTo(b,e);w.lineTo(c,f);w.lineTo(j,g);w.lineTo(h,k);w.lineTo(b,e);w.closePath()}function C(b,e,c,j){if(H!=e)w.lineWidth=H=e;if(D!=c)w.lineCap=D=c;if(Q!=j)w.lineJoin=Q=j;f(b);w.stroke();R.inflate(e*2)}function Ga(b){g(b);w.fill()}function Ea(b,e,c,f,j,g,h,k,m,t,n,o,W){var p,u;p=h.width-1;u=h.height-1;k*=p;m*=u;t*=p;n*=u;o*=p;W*=u;c-=b;f-=e;j-=b;g-=e;t-=k;n-=m;o-=k;W-=m;p=t*W-o*n;p!=0&&(u=1/p,p=(W*c-n*j)*u,n=(W*f-n*g)*u,c=(t*j-o*c)*u,f=(t*g-o*f)*u,b=b-p*
k-c*m,e=e-n*k-f*m,w.save(),w.transform(p,n,c,f,b,e),w.clip(),w.drawImage(h,0,0),w.restore())}function Ta(b,e,c,f){var j=~~(b.r*255),g=~~(b.g*255),b=~~(b.b*255),h=~~(e.r*255),k=~~(e.g*255),e=~~(e.b*255),m=~~(c.r*255),n=~~(c.g*255),c=~~(c.b*255),t=~~(f.r*255),o=~~(f.g*255),f=~~(f.b*255);wa[0]=j<0?0:j>255?255:j;wa[1]=g<0?0:g>255?255:g;wa[2]=b<0?0:b>255?255:b;wa[4]=h<0?0:h>255?255:h;wa[5]=k<0?0:k>255?255:k;wa[6]=e<0?0:e>255?255:e;wa[8]=m<0?0:m>255?255:m;wa[9]=n<0?0:n>255?255:n;wa[10]=c<0?0:c>255?255:
c;wa[12]=t<0?0:t>255?255:t;wa[13]=o<0?0:o>255?255:o;wa[14]=f<0?0:f>255?255:f;Qa.putImageData(Wa,0,0);Sa.drawImage(Pa,0,0);return Ra}function Ja(b,e,c){b=(b-e)/(c-e);return b*b*(3-2*b)}function Na(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}function E(b,e){var c=e.x-b.x,f=e.y-b.y,j=1/Math.sqrt(c*c+f*f);c*=j;f*=j;e.x+=c;e.y+=f;b.x-=c;b.y-=f}var Ua,x,ma,za,Ha,Oa,Va,ra;this.autoClear?this.clear():w.setTransform(1,0,0,-1,v,u);h.data.vertices=0;h.data.faces=0;m=n.projectScene(b,k,this.sortElements);(O=b.lights.length>
M
Mr.doob 已提交
173
0)&&o(b);Ua=0;for(x=m.length;Ua<x;Ua++){ma=m[Ua];R.empty();if(ma instanceof THREE.RenderableParticle){J=ma;J.x*=v;J.y*=u;za=0;for(Ha=ma.materials.length;za<Ha;)ra=ma.materials[za++],ra.opacity!=0&&t(J,ma,ra,b)}else if(ma instanceof THREE.RenderableLine){if(J=ma.v1,F=ma.v2,J.positionScreen.x*=v,J.positionScreen.y*=u,F.positionScreen.x*=v,F.positionScreen.y*=u,R.addPoint(J.positionScreen.x,J.positionScreen.y),R.addPoint(F.positionScreen.x,F.positionScreen.y),va.instersects(R)){za=0;for(Ha=ma.materials.length;za<
M
Mr.doob 已提交
174 175 176 177
Ha;)ra=ma.materials[za++],ra.opacity!=0&&y(J,F,ma,ra,b)}}else if(ma instanceof THREE.RenderableFace3){if(J=ma.v1,F=ma.v2,I=ma.v3,J.positionScreen.x*=v,J.positionScreen.y*=u,F.positionScreen.x*=v,F.positionScreen.y*=u,I.positionScreen.x*=v,I.positionScreen.y*=u,ma.overdraw&&(E(J.positionScreen,F.positionScreen),E(F.positionScreen,I.positionScreen),E(I.positionScreen,J.positionScreen)),R.add3Points(J.positionScreen.x,J.positionScreen.y,F.positionScreen.x,F.positionScreen.y,I.positionScreen.x,I.positionScreen.y),
va.instersects(R)){za=0;for(Ha=ma.meshMaterials.length;za<Ha;)if(ra=ma.meshMaterials[za++],ra instanceof THREE.MeshFaceMaterial){Oa=0;for(Va=ma.faceMaterials.length;Oa<Va;)(ra=ma.faceMaterials[Oa++])&&ra.opacity!=0&&A(J,F,I,0,1,2,ma,ra,b)}else ra.opacity!=0&&A(J,F,I,0,1,2,ma,ra,b)}}else if(ma instanceof THREE.RenderableFace4&&(J=ma.v1,F=ma.v2,I=ma.v3,S=ma.v4,J.positionScreen.x*=v,J.positionScreen.y*=u,F.positionScreen.x*=v,F.positionScreen.y*=u,I.positionScreen.x*=v,I.positionScreen.y*=u,S.positionScreen.x*=
v,S.positionScreen.y*=u,K.positionScreen.copy(F.positionScreen),ea.positionScreen.copy(S.positionScreen),ma.overdraw&&(E(J.positionScreen,F.positionScreen),E(F.positionScreen,S.positionScreen),E(S.positionScreen,J.positionScreen),E(I.positionScreen,K.positionScreen),E(I.positionScreen,ea.positionScreen)),R.addPoint(J.positionScreen.x,J.positionScreen.y),R.addPoint(F.positionScreen.x,F.positionScreen.y),R.addPoint(I.positionScreen.x,I.positionScreen.y),R.addPoint(S.positionScreen.x,S.positionScreen.y),
va.instersects(R))){za=0;for(Ha=ma.meshMaterials.length;za<Ha;)if(ra=ma.meshMaterials[za++],ra instanceof THREE.MeshFaceMaterial){Oa=0;for(Va=ma.faceMaterials.length;Oa<Va;)(ra=ma.faceMaterials[Oa++])&&ra.opacity!=0&&B(J,F,I,S,K,ea,ma,ra,b)}else ra.opacity!=0&&B(J,F,I,S,K,ea,ma,ra,b)}qa.addRectangle(R)}w.setTransform(1,0,0,1,0,0)}};
178 179 180 181 182 183 184 185 186
THREE.SVGRenderer=function(){function b(b,e,c){var f,j,g,h;f=0;for(j=b.lights.length;f<j;f++)g=b.lights[f],g instanceof THREE.DirectionalLight?(h=e.normalWorld.dot(g.position)*g.intensity,h>0&&(c.r+=g.color.r*h,c.g+=g.color.g*h,c.b+=g.color.b*h)):g instanceof THREE.PointLight&&(S.sub(g.position,e.centroidWorld),S.normalize(),h=e.normalWorld.dot(S)*g.intensity,h>0&&(c.r+=g.color.r*h,c.g+=g.color.g*h,c.b+=g.color.b*h))}function c(e,c,m,n,t,o){h.data.vertices+=3;h.data.faces++;j=f(ca++);j.setAttribute("d",
"M "+e.positionScreen.x+" "+e.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+m.positionScreen.x+","+m.positionScreen.y+"z");t instanceof THREE.MeshBasicMaterial?H.hex=t.color.hex:t instanceof THREE.MeshLambertMaterial?C?(D.r=Q.r,D.g=Q.g,D.b=Q.b,b(o,n,D),H.r=Math.max(0,Math.min(t.color.r*D.r,1)),H.g=Math.max(0,Math.min(t.color.g*D.g,1)),H.b=Math.max(0,Math.min(t.color.b*D.b,1)),H.updateHex()):H.hex=t.color.hex:t instanceof THREE.MeshDepthMaterial?(I=1-t.__2near/(t.__farPlusNear-
n.z*t.__farMinusNear),H.setRGB(I,I,I)):t instanceof THREE.MeshNormalMaterial&&H.setRGB(g(n.normalWorld.x),g(n.normalWorld.y),g(n.normalWorld.z));t.wireframe?j.setAttribute("style","fill: none; stroke: #"+k(H.hex.toString(16))+"; stroke-width: "+t.wireframeLinewidth+"; stroke-opacity: "+t.opacity+"; stroke-linecap: "+t.wireframeLinecap+"; stroke-linejoin: "+t.wireframeLinejoin):j.setAttribute("style","fill: #"+k(H.hex.toString(16))+"; fill-opacity: "+t.opacity);p.appendChild(j)}function e(e,c,m,t,
n,o,u){h.data.vertices+=4;h.data.faces++;j=f(ca++);j.setAttribute("d","M "+e.positionScreen.x+" "+e.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+m.positionScreen.x+","+m.positionScreen.y+" L "+t.positionScreen.x+","+t.positionScreen.y+"z");o instanceof THREE.MeshBasicMaterial?H.hex=o.color.hex:o instanceof THREE.MeshLambertMaterial?C?(D.r=Q.r,D.g=Q.g,D.b=Q.b,b(u,n,D),H.r=Math.max(0,Math.min(o.color.r*D.r,1)),H.g=Math.max(0,Math.min(o.color.g*D.g,1)),H.b=Math.max(0,Math.min(o.color.b*
D.b,1)),H.updateHex()):H.hex=o.color.hex:o instanceof THREE.MeshDepthMaterial?(I=1-o.__2near/(o.__farPlusNear-n.z*o.__farMinusNear),H.setRGB(I,I,I)):o instanceof THREE.MeshNormalMaterial&&H.setRGB(g(n.normalWorld.x),g(n.normalWorld.y),g(n.normalWorld.z));o.wireframe?j.setAttribute("style","fill: none; stroke: #"+k(H.hex.toString(16))+"; stroke-width: "+o.wireframeLinewidth+"; stroke-opacity: "+o.opacity+"; stroke-linecap: "+o.wireframeLinecap+"; stroke-linejoin: "+o.wireframeLinejoin):j.setAttribute("style",
"fill: #"+k(H.hex.toString(16))+"; fill-opacity: "+o.opacity);p.appendChild(j)}function f(b){K[b]==null&&(K[b]=document.createElementNS("http://www.w3.org/2000/svg","path"),Z==0&&K[b].setAttribute("shape-rendering","crispEdges"));return K[b]}function g(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}function k(b){for(;b.length<6;)b="0"+b;return b}var h=this,m=null,n=new THREE.Projector,p=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,t,v,u,w,B,A,y,G=new THREE.Rectangle,z=new THREE.Rectangle,C=
!1,H=new THREE.Color(16777215),D=new THREE.Color(16777215),Q=new THREE.Color(0),J=new THREE.Color(0),F=new THREE.Color(0),I,S=new THREE.Vector3,K=[],ea=[],j,ca,T,Z=1;this.domElement=p;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,faces:0};this.setQuality=function(b){switch(b){case "high":Z=1;break;case "low":Z=0}};this.setSize=function(b,e){o=b;t=e;v=o/2;u=t/2;p.setAttribute("viewBox",-v+" "+-u+" "+o+" "+t);p.setAttribute("width",o);p.setAttribute("height",t);G.set(-v,
-u,v,u)};this.clear=function(){for(;p.childNodes.length>0;)p.removeChild(p.childNodes[0])};this.render=function(b,f){var g,t,o,H,D,I,L,K;this.autoClear&&this.clear();h.data.vertices=0;h.data.faces=0;m=n.projectScene(b,f,this.sortElements);T=ca=0;if(C=b.lights.length>0){L=b.lights;Q.setRGB(0,0,0);J.setRGB(0,0,0);F.setRGB(0,0,0);g=0;for(t=L.length;g<t;g++)o=L[g],H=o.color,o instanceof THREE.AmbientLight?(Q.r+=H.r,Q.g+=H.g,Q.b+=H.b):o instanceof THREE.DirectionalLight?(J.r+=H.r,J.g+=H.g,J.b+=H.b):o instanceof
THREE.PointLight&&(F.r+=H.r,F.g+=H.g,F.b+=H.b)}g=0;for(t=m.length;g<t;g++)if(L=m[g],z.empty(),L instanceof THREE.RenderableParticle){w=L;w.x*=v;w.y*=-u;o=0;for(H=L.materials.length;o<H;)o++}else if(L instanceof THREE.RenderableLine){if(w=L.v1,B=L.v2,w.positionScreen.x*=v,w.positionScreen.y*=-u,B.positionScreen.x*=v,B.positionScreen.y*=-u,z.addPoint(w.positionScreen.x,w.positionScreen.y),z.addPoint(B.positionScreen.x,B.positionScreen.y),G.instersects(z)){o=0;for(H=L.materials.length;o<H;)if((K=L.materials[o++])&&
M
Mr.doob 已提交
187
K.opacity!=0){D=w;I=B;var S=T++;ea[S]==null&&(ea[S]=document.createElementNS("http://www.w3.org/2000/svg","line"),Z==0&&ea[S].setAttribute("shape-rendering","crispEdges"));j=ea[S];j.setAttribute("x1",D.positionScreen.x);j.setAttribute("y1",D.positionScreen.y);j.setAttribute("x2",I.positionScreen.x);j.setAttribute("y2",I.positionScreen.y);K instanceof THREE.LineBasicMaterial&&(j.setAttribute("style","fill: none; stroke: ##"+k(K.color.hex.toString(16))+"; stroke-width: "+K.linewidth+"; stroke-opacity: "+
188 189 190
K.opacity+"; stroke-linecap: "+K.linecap+"; stroke-linejoin: "+K.linejoin),p.appendChild(j))}}}else if(L instanceof THREE.RenderableFace3){if(w=L.v1,B=L.v2,A=L.v3,w.positionScreen.x*=v,w.positionScreen.y*=-u,B.positionScreen.x*=v,B.positionScreen.y*=-u,A.positionScreen.x*=v,A.positionScreen.y*=-u,z.addPoint(w.positionScreen.x,w.positionScreen.y),z.addPoint(B.positionScreen.x,B.positionScreen.y),z.addPoint(A.positionScreen.x,A.positionScreen.y),G.instersects(z)){o=0;for(H=L.meshMaterials.length;o<
H;)if(K=L.meshMaterials[o++],K instanceof THREE.MeshFaceMaterial){D=0;for(I=L.faceMaterials.length;D<I;)(K=L.faceMaterials[D++])&&K.opacity!=0&&c(w,B,A,L,K,b)}else K&&K.opacity!=0&&c(w,B,A,L,K,b)}}else if(L instanceof THREE.RenderableFace4&&(w=L.v1,B=L.v2,A=L.v3,y=L.v4,w.positionScreen.x*=v,w.positionScreen.y*=-u,B.positionScreen.x*=v,B.positionScreen.y*=-u,A.positionScreen.x*=v,A.positionScreen.y*=-u,y.positionScreen.x*=v,y.positionScreen.y*=-u,z.addPoint(w.positionScreen.x,w.positionScreen.y),z.addPoint(B.positionScreen.x,
B.positionScreen.y),z.addPoint(A.positionScreen.x,A.positionScreen.y),z.addPoint(y.positionScreen.x,y.positionScreen.y),G.instersects(z))){o=0;for(H=L.meshMaterials.length;o<H;)if(K=L.meshMaterials[o++],K instanceof THREE.MeshFaceMaterial){D=0;for(I=L.faceMaterials.length;D<I;)(K=L.faceMaterials[D++])&&K.opacity!=0&&e(w,B,A,y,L,K,b)}else K&&K.opacity!=0&&e(w,B,A,y,L,K,b)}}};
191 192 193
THREE.ShaderChunk={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",
envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube envMap;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( envMap, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refractionRatio;\nuniform bool useRefract;\n#endif",
envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",
M
Mr.doob 已提交
194
map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform vec4 offsetRepeat;\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D lightMap;\n#endif",
195 196
lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nfloat pointLightWeighting = max( dot( transformedNormal, lVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting * lDistance;\n#ifdef PHONG\nvPointLight[ i ] = vec4( lVector, lDistance );\n#endif\n}\n#endif\n}",
197
lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec4 vPointLight[ 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( vPointLight[ i ].xyz );\nvec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );\nfloat pointDistance = vPointLight[ i ].w;\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse  += mColor * pointDiffuseWeight * pointDistance;\npointSpecular += mSpecular * pointSpecularWeight * pointDistance;\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 + viewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse  += 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;",
198 199
color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\nvColor = color;\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\nuniform mat4 boneGlobalMatrices[ MAX_BONES ];\n#endif",skinning_vertex:"#ifdef USE_SKINNING\ngl_Position  = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;\ngl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;\ngl_Position  = projectionMatrix * viewMatrix * objectMatrix * gl_Position;\n#endif",
morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\nuniform float morphTargetInfluences[ 8 ];\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\nvec3 morphed = vec3( 0.0, 0.0, 0.0 );\nmorphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\nmorphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\nmorphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\nmorphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\nmorphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\nmorphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\nmorphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\nmorphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\nmorphed += position;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );\n#endif",
M
Mr.doob 已提交
200
default_vertex:"#ifndef USE_MORPHTARGETS\n#ifndef USE_SKINNING\ngl_Position = projectionMatrix * mvPosition;\n#endif\n#endif"};THREE.UniformsUtils={merge:function(b){var c,e,f,g={};for(c=0;c<b.length;c++)for(e in f=this.clone(b[c]),f)g[e]=f[e];return g},clone:function(b){var c,e,f,g={};for(c in b)for(e in g[c]={},b[c])f=b[c][e],g[c][e]=f instanceof THREE.Color||f instanceof THREE.Vector3||f instanceof THREE.Texture?f.clone():f;return g}};
A
alteredq 已提交
201 202 203
THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},offsetRepeat:{type:"v4",value:new THREE.Vector4(0,0,1,1)},lightMap:{type:"t",value:2,texture:null},envMap:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refractionRatio:{type:"f",value:0.98},combine:{type:"i",value:0},morphTargetInfluences:{type:"f",value:0}},fog:{fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",
value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{enableLighting:{type:"i",value:1},ambientLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightDistance:{type:"fv1",value:[]}},particle:{psColor:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},size:{type:"f",value:1},scale:{type:"f",
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)}}};
M
Mr.doob 已提交
204 205 206 207
THREE.ShaderLib={lensFlareVertexTexture:{vertexShader:"uniform vec3 screenPosition;\nuniform vec2 scale;\nuniform float rotation;\nuniform int renderType;\nuniform sampler2D occlusionMap;\nattribute vec2 position;\nattribute vec2 UV;\nvarying vec2 vUV;\nvarying float vVisibility;\nvoid main() {\nvUV = UV;\nvec2 pos = position;\nif( renderType == 2 ) {\nvec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.5 ) );\nvVisibility = (       visibility.r / 9.0 ) *\n( 1.0 - visibility.g / 9.0 ) *\n(       visibility.b / 9.0 ) *\n( 1.0 - visibility.a / 9.0 );\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform sampler2D map;\nuniform float opacity;\nuniform int renderType;\nvarying vec2 vUV;\nvarying float vVisibility;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity * vVisibility;\ngl_FragColor = color;\n}\n}"},
lensFlare:{vertexShader:"uniform vec3 screenPosition;\nuniform vec2 scale;\nuniform float rotation;\nuniform int renderType;\nattribute vec2 position;\nattribute vec2 UV;\nvarying vec2 vUV;\nvoid main() {\nvUV = UV;\nvec2 pos = position;\nif( renderType == 2 ) {\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform sampler2D map;\nuniform sampler2D occlusionMap;\nuniform float opacity;\nuniform int renderType;\nvarying vec2 vUV;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nfloat visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;\nvisibility = ( 1.0 - visibility / 4.0 );\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity * visibility;\ngl_FragColor = color;\n}\n}"},
sprite:{vertexShader:"uniform int useScreenCoordinates;\nuniform int affectedByDistance;\nuniform vec3 screenPosition;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform float rotation;\nuniform vec2 scale;\nuniform vec2 alignment;\nuniform vec2 uvOffset;\nuniform vec2 uvScale;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\nvUV = uvOffset + uv * uvScale;\nvec2 alignedPosition = position + alignment;\nvec2 rotatedPosition;\nrotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;\nrotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;\nvec4 finalPosition;\nif( useScreenCoordinates != 0 ) {\nfinalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );\n} else {\nfinalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\nfinalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );\n}\ngl_Position = finalPosition;\n}",
fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform sampler2D map;\nuniform float opacity;\nvarying vec2 vUV;\nvoid main() {\nvec4 color = texture2D( map, vUV );\ncolor.a *= opacity;\ngl_FragColor = color;\n}"},shadowPost:{vertexShader:"uniform \tmat4 \tprojectionMatrix;\nattribute \tvec3 \tposition;\nvoid main() {\ngl_Position = projectionMatrix * vec4( position, 1.0 );\n}",fragmentShader:"#ifdef GL_ES\nprecision highp float;\n#endif\nuniform \tfloat \tdarkness;\nvoid main() {\ngl_FragColor = vec4( 0, 0, 0, darkness );\n}"},
M
Mr.doob 已提交
208
shadowVolumeDynamic:{uniforms:{directionalLightDirection:{type:"fv",value:[]}},vertexShader:"uniform \tvec3 \tdirectionalLightDirection;\nvoid main() {\nvec4 pos      = objectMatrix * vec4( position, 1.0 );\nvec3 norm     = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 extruded = vec4( directionalLightDirection * 5000.0 * step( 0.0, dot( directionalLightDirection, norm ) ), 0.0 );\ngl_Position   = projectionMatrix * viewMatrix * ( pos + extruded );\n}",fragmentShader:"void main() {\ngl_FragColor = vec4( 1.0 );\n}"},
209
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}},
A
alteredq 已提交
210 211 212 213 214 215 216 217 218 219 220
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.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog]),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;",
THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:[THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,
THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,"}"].join("\n")},lambert:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,
THREE.UniformsLib.fog,THREE.UniformsLib.lights]),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;\nvarying vec3 vLightWeighting;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );\ngl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.lightmap_fragment,
THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:["varying vec3 vLightWeighting;",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,
THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,"vec3 transformedNormal = normalize( normalMatrix * normal );",THREE.ShaderChunk.lights_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,"}"].join("\n")},phong:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,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.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.lights_pars_fragment,"void main() {\ngl_FragColor = vec4( vLightWeighting, 1.0 );",THREE.ShaderChunk.lights_fragment,
THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:["#define PHONG\nvarying vec3 vLightWeighting;\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,
THREE.ShaderChunk.morphtarget_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 transformedNormal = normalize( normalMatrix * normal );\nvNormal = transformedNormal;",THREE.ShaderChunk.lights_vertex,
THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,"}"].join("\n")},particle_basic:{uniforms:THREE.UniformsLib.particle,fragmentShader:["uniform vec3 psColor;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_particle_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( psColor, opacity );",THREE.ShaderChunk.map_particle_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.fog_fragment,
"}"].join("\n"),vertexShader:["uniform float size;\nuniform float scale;",THREE.ShaderChunk.color_pars_vertex,"void main() {",THREE.ShaderChunk.color_vertex,"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n#ifdef USE_SIZEATTENUATION\ngl_PointSize = size * ( scale / length( mvPosition.xyz ) );\n#else\ngl_PointSize = size;\n#endif\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n")}};
221 222 223 224 225
THREE.WebGLRenderer=function(b){function c(b,e,c){var f,g,h,k=b.vertices,m=k.length,o=b.colors,t=o.length,n=b.__vertexArray,p=b.__colorArray,u=b.__sortArray,v=b.__dirtyVertices,w=b.__dirtyColors;if(c.sortParticles){Y.multiplySelf(c.matrixWorld);for(f=0;f<m;f++)g=k[f].position,ga.copy(g),Y.multiplyVector3(ga),u[f]=[ga.z,f];u.sort(function(b,e){return e[0]-b[0]});for(f=0;f<m;f++)g=k[u[f][1]].position,h=f*3,n[h]=g.x,n[h+1]=g.y,n[h+2]=g.z;for(f=0;f<t;f++)h=f*3,color=o[u[f][1]],p[h]=color.r,p[h+1]=color.g,
p[h+2]=color.b}else{if(v)for(f=0;f<m;f++)g=k[f].position,h=f*3,n[h]=g.x,n[h+1]=g.y,n[h+2]=g.z;if(w)for(f=0;f<t;f++)color=o[f],h=f*3,p[h]=color.r,p[h+1]=color.g,p[h+2]=color.b}if(v||c.sortParticles)j.bindBuffer(j.ARRAY_BUFFER,b.__webglVertexBuffer),j.bufferData(j.ARRAY_BUFFER,n,e);if(w||c.sortParticles)j.bindBuffer(j.ARRAY_BUFFER,b.__webglColorBuffer),j.bufferData(j.ARRAY_BUFFER,p,e)}function e(b,e,c,f,g){f.program||ea.initMaterial(f,e,c,g);var h=f.program,k=h.uniforms,m=f.uniforms;h!=T&&(j.useProgram(h),
T=h);j.uniformMatrix4fv(k.projectionMatrix,!1,ka);if(c&&(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial||f instanceof THREE.LineBasicMaterial||f instanceof THREE.ParticleBasicMaterial||f.fog))if(m.fogColor.value=c.color,c instanceof THREE.Fog)m.fogNear.value=c.near,m.fogFar.value=c.far;else if(c instanceof THREE.FogExp2)m.fogDensity.value=c.density;if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f.lights){var o,
t,n=0,p=0,u=0,v,w,y,A,B=Da,z=B.directional.colors,H=B.directional.positions,G=B.point.colors,D=B.point.positions,Y=B.point.distances,C=0,E=0,c=t=A=0;for(o=e.length;c<o;c++)if(t=e[c],v=t.color,w=t.position,y=t.intensity,A=t.distance,t instanceof THREE.AmbientLight)n+=v.r,p+=v.g,u+=v.b;else if(t instanceof THREE.DirectionalLight)A=C*3,z[A]=v.r*y,z[A+1]=v.g*y,z[A+2]=v.b*y,H[A]=w.x,H[A+1]=w.y,H[A+2]=w.z,C+=1;else if(t instanceof THREE.PointLight)t=E*3,G[t]=v.r*y,G[t+1]=v.g*y,G[t+2]=v.b*y,D[t]=w.x,D[t+
1]=w.y,D[t+2]=w.z,Y[E]=A,E+=1;for(c=C*3;c<z.length;c++)z[c]=0;for(c=E*3;c<G.length;c++)G[c]=0;B.point.length=E;B.directional.length=C;B.ambient[0]=n;B.ambient[1]=p;B.ambient[2]=u;c=Da;m.enableLighting.value=c.directional.length+c.point.length;m.ambientLightColor.value=c.ambient;m.directionalLightColor.value=c.directional.colors;m.directionalLightDirection.value=c.directional.positions;m.pointLightColor.value=c.point.colors;m.pointLightPosition.value=c.point.positions;m.pointLightDistance.value=c.point.distances}if(f instanceof
M
Mr.doob 已提交
226 227
THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial)m.diffuse.value=f.color,m.opacity.value=f.opacity,(m.map.texture=f.map)&&m.offsetRepeat.value.set(f.map.offset.x,f.map.offset.y,f.map.repeat.x,f.map.repeat.y),m.lightMap.texture=f.lightMap,m.envMap.texture=f.envMap,m.reflectivity.value=f.reflectivity,m.refractionRatio.value=f.refractionRatio,m.combine.value=f.combine,m.useRefract.value=f.envMap&&f.envMap.mapping instanceof THREE.CubeRefractionMapping;
if(f instanceof THREE.LineBasicMaterial)m.diffuse.value=f.color,m.opacity.value=f.opacity;else if(f instanceof THREE.ParticleBasicMaterial)m.psColor.value=f.color,m.opacity.value=f.opacity,m.size.value=f.size,m.scale.value=ua.height/2,m.map.texture=f.map;else if(f instanceof THREE.MeshPhongMaterial)m.ambient.value=f.ambient,m.specular.value=f.specular,m.shininess.value=f.shininess;else if(f instanceof THREE.MeshDepthMaterial)m.mNear.value=b.near,m.mFar.value=b.far,m.opacity.value=f.opacity;else if(f instanceof
228 229 230
THREE.MeshNormalMaterial)m.opacity.value=f.opacity;for(var F in m)if(p=h.uniforms[F])if(o=m[F],n=o.type,c=o.value,n=="i")j.uniform1i(p,c);else if(n=="f")j.uniform1f(p,c);else if(n=="fv1")j.uniform1fv(p,c);else if(n=="fv")j.uniform3fv(p,c);else if(n=="v2")j.uniform2f(p,c.x,c.y);else if(n=="v3")j.uniform3f(p,c.x,c.y,c.z);else if(n=="v4")j.uniform4f(p,c.x,c.y,c.z,c.w);else if(n=="c")j.uniform3f(p,c.r,c.g,c.b);else if(n=="t"&&(j.uniform1i(p,c),o=o.texture))if(o.image instanceof Array&&o.image.length==
6){if(o.image.length==6){if(o.needsUpdate){if(o.__webglInit){j.bindTexture(j.TEXTURE_CUBE_MAP,o.image.__webglTextureCube);for(n=0;n<6;++n)j.texSubImage2D(j.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,0,0,j.RGBA,j.UNSIGNED_BYTE,o.image[n])}else{o.image.__webglTextureCube=j.createTexture();j.bindTexture(j.TEXTURE_CUBE_MAP,o.image.__webglTextureCube);for(n=0;n<6;++n)j.texImage2D(j.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,j.RGBA,j.RGBA,j.UNSIGNED_BYTE,o.image[n]);o.__webglInit=!0}Q(j.TEXTURE_CUBE_MAP,o,o.image[0]);j.bindTexture(j.TEXTURE_CUBE_MAP,
null);o.needsUpdate=!1}j.activeTexture(j.TEXTURE0+c);j.bindTexture(j.TEXTURE_CUBE_MAP,o.image.__webglTextureCube)}}else J(o,c);j.uniformMatrix4fv(k.modelViewMatrix,!1,g._modelViewMatrixArray);j.uniformMatrix3fv(k.normalMatrix,!1,g._normalMatrixArray);(f instanceof THREE.MeshShaderMaterial||f instanceof THREE.MeshPhongMaterial||f.envMap)&&k.cameraPosition!==null&&j.uniform3f(k.cameraPosition,b.position.x,b.position.y,b.position.z);(f instanceof THREE.MeshShaderMaterial||f.envMap||f.skinning)&&k.objectMatrix!==
M
Mr.doob 已提交
231 232
null&&j.uniformMatrix4fv(k.objectMatrix,!1,g._objectMatrixArray);(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshShaderMaterial||f.skinning)&&k.viewMatrix!==null&&j.uniformMatrix4fv(k.viewMatrix,!1,la);if(f instanceof THREE.ShadowVolumeDynamicMaterial)b=m.directionalLightDirection.value,b[0]=-e[1].position.x,b[1]=-e[1].position.y,b[2]=-e[1].position.z,j.uniform3fv(k.directionalLightDirection,b),j.uniformMatrix4fv(k.objectMatrix,!1,g._objectMatrixArray),
j.uniformMatrix4fv(k.viewMatrix,!1,la);f.skinning&&(j.uniformMatrix4fv(k.cameraInverseMatrix,!1,la),j.uniformMatrix4fv(k.boneGlobalMatrices,!1,g.boneMatrices));return h}function f(b,c,f,g,h,k){if(g.opacity!=0){var m,b=e(b,c,f,g,k).attributes;if(!g.morphTargets&&b.position>=0)j.bindBuffer(j.ARRAY_BUFFER,h.__webglVertexBuffer),j.vertexAttribPointer(b.position,3,j.FLOAT,!1,0,0);else{c=g.program.attributes;k.morphTargetBase!==-1?(j.bindBuffer(j.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[k.morphTargetBase]),
233 234
j.vertexAttribPointer(c.position,3,j.FLOAT,!1,0,0)):c.position>=0&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglVertexBuffer),j.vertexAttribPointer(c.position,3,j.FLOAT,!1,0,0));if(k.morphTargetForcedOrder.length)for(var f=0,o=k.morphTargetForcedOrder,t=k.morphTargetInfluences;f<g.numSupportedMorphTargets&&f<o.length;)j.bindBuffer(j.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[o[f]]),j.vertexAttribPointer(c["morphTarget"+f],3,j.FLOAT,!1,0,0),k.__webglMorphTargetInfluences[f]=t[o[f]],f++;else{var o=[],n=-1,
p=0,t=k.morphTargetInfluences,u,v=t.length,f=0;for(k.morphTargetBase!==-1&&(o[k.morphTargetBase]=!0);f<g.numSupportedMorphTargets;){for(u=0;u<v;u++)!o[u]&&t[u]>n&&(p=u,n=t[p]);j.bindBuffer(j.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[p]);j.vertexAttribPointer(c["morphTarget"+f],3,j.FLOAT,!1,0,0);k.__webglMorphTargetInfluences[f]=n;o[p]=1;n=-1;f++}}g.program.uniforms.morphTargetInfluences!==null&&j.uniform1fv(g.program.uniforms.morphTargetInfluences,k.__webglMorphTargetInfluences)}if(h.__webglCustomAttributes)for(m in h.__webglCustomAttributes)b[m]>=
M
Mr.doob 已提交
235 236 237 238 239
0&&(c=h.__webglCustomAttributes[m],j.bindBuffer(j.ARRAY_BUFFER,c.buffer),j.vertexAttribPointer(b[m],c.size,j.FLOAT,!1,0,0));b.color>=0&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglColorBuffer),j.vertexAttribPointer(b.color,3,j.FLOAT,!1,0,0));b.normal>=0&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglNormalBuffer),j.vertexAttribPointer(b.normal,3,j.FLOAT,!1,0,0));b.tangent>=0&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglTangentBuffer),j.vertexAttribPointer(b.tangent,4,j.FLOAT,!1,0,0));b.uv>=0&&(h.__webglUVBuffer?(j.bindBuffer(j.ARRAY_BUFFER,
h.__webglUVBuffer),j.vertexAttribPointer(b.uv,2,j.FLOAT,!1,0,0),j.enableVertexAttribArray(b.uv)):j.disableVertexAttribArray(b.uv));b.uv2>=0&&(h.__webglUV2Buffer?(j.bindBuffer(j.ARRAY_BUFFER,h.__webglUV2Buffer),j.vertexAttribPointer(b.uv2,2,j.FLOAT,!1,0,0),j.enableVertexAttribArray(b.uv2)):j.disableVertexAttribArray(b.uv2));g.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglSkinVertexABuffer),j.vertexAttribPointer(b.skinVertexA,4,
j.FLOAT,!1,0,0),j.bindBuffer(j.ARRAY_BUFFER,h.__webglSkinVertexBBuffer),j.vertexAttribPointer(b.skinVertexB,4,j.FLOAT,!1,0,0),j.bindBuffer(j.ARRAY_BUFFER,h.__webglSkinIndicesBuffer),j.vertexAttribPointer(b.skinIndex,4,j.FLOAT,!1,0,0),j.bindBuffer(j.ARRAY_BUFFER,h.__webglSkinWeightsBuffer),j.vertexAttribPointer(b.skinWeight,4,j.FLOAT,!1,0,0));k instanceof THREE.Mesh?(g.wireframe?(j.lineWidth(g.wireframeLinewidth),j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,h.__webglLineBuffer),j.drawElements(j.LINES,h.__webglLineCount,
j.UNSIGNED_SHORT,0)):(j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,h.__webglFaceBuffer),j.drawElements(j.TRIANGLES,h.__webglFaceCount,j.UNSIGNED_SHORT,0)),ea.data.vertices+=h.__webglFaceCount,ea.data.faces+=h.__webglFaceCount/3,ea.data.drawCalls++):k instanceof THREE.Line?(k=k.type==THREE.LineStrip?j.LINE_STRIP:j.LINES,j.lineWidth(g.linewidth),j.drawArrays(k,0,h.__webglLineCount),ea.data.drawCalls++):k instanceof THREE.ParticleSystem?(j.drawArrays(j.POINTS,0,h.__webglParticleCount),ea.data.drawCalls++):k instanceof
THREE.Ribbon&&(j.drawArrays(j.TRIANGLE_STRIP,0,h.__webglVertexCount),ea.data.drawCalls++)}}function g(b,e,c){if(!b.__webglVertexBuffer)b.__webglVertexBuffer=j.createBuffer();if(!b.__webglNormalBuffer)b.__webglNormalBuffer=j.createBuffer();b.hasPos&&(j.bindBuffer(j.ARRAY_BUFFER,b.__webglVertexBuffer),j.bufferData(j.ARRAY_BUFFER,b.positionArray,j.DYNAMIC_DRAW),j.enableVertexAttribArray(e.attributes.position),j.vertexAttribPointer(e.attributes.position,3,j.FLOAT,!1,0,0));if(b.hasNormal){j.bindBuffer(j.ARRAY_BUFFER,
240
b.__webglNormalBuffer);if(c==THREE.FlatShading){var f,g,h,k,m,o,t,n,p,u,v=b.count*3;for(u=0;u<v;u+=9)c=b.normalArray,f=c[u],g=c[u+1],h=c[u+2],k=c[u+3],o=c[u+4],n=c[u+5],m=c[u+6],t=c[u+7],p=c[u+8],f=(f+k+m)/3,g=(g+o+t)/3,h=(h+n+p)/3,c[u]=f,c[u+1]=g,c[u+2]=h,c[u+3]=f,c[u+4]=g,c[u+5]=h,c[u+6]=f,c[u+7]=g,c[u+8]=h}j.bufferData(j.ARRAY_BUFFER,b.normalArray,j.DYNAMIC_DRAW);j.enableVertexAttribArray(e.attributes.normal);j.vertexAttribPointer(e.attributes.normal,3,j.FLOAT,!1,0,0)}j.drawArrays(j.TRIANGLES,
M
Mr.doob 已提交
241
0,b.count);b.count=0}function k(b){if(da!=b.doubleSided)b.doubleSided?j.disable(j.CULL_FACE):j.enable(j.CULL_FACE),da=b.doubleSided;if(X!=b.flipSided)b.flipSided?j.frontFace(j.CW):j.frontFace(j.CCW),X=b.flipSided}function h(b){ia!=b&&(b?j.enable(j.DEPTH_TEST):j.disable(j.DEPTH_TEST),ia=b)}function m(b,e,c){ha!=b&&(b?j.enable(j.POLYGON_OFFSET_FILL):j.disable(j.POLYGON_OFFSET_FILL),ha=b);if(b&&(na!=e||ja!=c))j.polygonOffset(e,c),na=e,ja=c}function n(b){$[0].set(b.n41-b.n11,b.n42-b.n12,b.n43-b.n13,b.n44-
242 243 244 245 246
b.n14);$[1].set(b.n41+b.n11,b.n42+b.n12,b.n43+b.n13,b.n44+b.n14);$[2].set(b.n41+b.n21,b.n42+b.n22,b.n43+b.n23,b.n44+b.n24);$[3].set(b.n41-b.n21,b.n42-b.n22,b.n43-b.n23,b.n44-b.n24);$[4].set(b.n41-b.n31,b.n42-b.n32,b.n43-b.n33,b.n44-b.n34);$[5].set(b.n41+b.n31,b.n42+b.n32,b.n43+b.n33,b.n44+b.n34);for(var e,b=0;b<6;b++)e=$[b],e.divideScalar(Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z))}function p(b){for(var e=b.matrixWorld,c=-b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)),
f=0;f<6;f++)if(b=$[f].x*e.n14+$[f].y*e.n24+$[f].z*e.n34+$[f].w,b<=c)return!1;return!0}function o(b,e){b.list[b.count]=e;b.count+=1}function t(b){var e,c,f=b.object,g=b.opaque,h=b.transparent;h.count=0;b=g.count=0;for(e=f.materials.length;b<e;b++)c=f.materials[b],c.transparent?o(h,c):o(g,c)}function v(b){var e,c,f,g,h=b.object,j=b.buffer,k=b.opaque,m=b.transparent;m.count=0;b=k.count=0;for(f=h.materials.length;b<f;b++)if(e=h.materials[b],e instanceof THREE.MeshFaceMaterial){e=0;for(c=j.materials.length;e<
c;e++)(g=j.materials[e])&&(g.transparent?o(m,g):o(k,g))}else(g=e)&&(g.transparent?o(m,g):o(k,g))}function u(b,e){return e.z-b.z}function w(b){j.enable(j.POLYGON_OFFSET_FILL);j.polygonOffset(0.1,1);j.enable(j.STENCIL_TEST);j.enable(j.DEPTH_TEST);j.depthMask(!1);j.colorMask(!1,!1,!1,!1);j.stencilFunc(j.ALWAYS,1,255);j.stencilOpSeparate(j.BACK,j.KEEP,j.INCR,j.KEEP);j.stencilOpSeparate(j.FRONT,j.KEEP,j.DECR,j.KEEP);var e,c=b.lights.length,f,g=b.lights,h=[],k,m,o,t,n,p=b.__webglShadowVolumes.length;for(e=
0;e<c;e++)if(f=b.lights[e],f instanceof THREE.DirectionalLight&&f.castShadow){h[0]=-f.position.x;h[1]=-f.position.y;h[2]=-f.position.z;for(n=0;n<p;n++)f=b.__webglShadowVolumes[n].object,k=b.__webglShadowVolumes[n].buffer,m=f.materials[0],m.program||ea.initMaterial(m,g,void 0,f),m=m.program,o=m.uniforms,t=m.attributes,T!==m&&(j.useProgram(m),T=m,j.uniformMatrix4fv(o.projectionMatrix,!1,ka),j.uniformMatrix4fv(o.viewMatrix,!1,la),j.uniform3fv(o.directionalLightDirection,h)),f.matrixWorld.flattenToArray(f._objectMatrixArray),
j.uniformMatrix4fv(o.objectMatrix,!1,f._objectMatrixArray),j.bindBuffer(j.ARRAY_BUFFER,k.__webglVertexBuffer),j.vertexAttribPointer(t.position,3,j.FLOAT,!1,0,0),j.bindBuffer(j.ARRAY_BUFFER,k.__webglNormalBuffer),j.vertexAttribPointer(t.normal,3,j.FLOAT,!1,0,0),j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,k.__webglFaceBuffer),j.cullFace(j.FRONT),j.drawElements(j.TRIANGLES,k.__webglFaceCount,j.UNSIGNED_SHORT,0),j.cullFace(j.BACK),j.drawElements(j.TRIANGLES,k.__webglFaceCount,j.UNSIGNED_SHORT,0)}j.disable(j.POLYGON_OFFSET_FILL);
M
Mr.doob 已提交
247
j.colorMask(!0,!0,!0,!0);j.stencilFunc(j.NOTEQUAL,0,255);j.stencilOp(j.KEEP,j.KEEP,j.KEEP);j.disable(j.DEPTH_TEST);aa=-1;T=R.program;j.useProgram(R.program);j.uniformMatrix4fv(R.projectionLocation,!1,ka);j.uniform1f(R.darknessLocation,R.darkness);j.bindBuffer(j.ARRAY_BUFFER,R.vertexBuffer);j.vertexAttribPointer(R.vertexLocation,3,j.FLOAT,!1,0,0);j.enableVertexAttribArray(R.vertexLocation);j.blendFunc(j.ONE,j.ONE_MINUS_SRC_ALPHA);j.blendEquation(j.FUNC_ADD);j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,R.elementBuffer);
248
j.drawElements(j.TRIANGLES,6,j.UNSIGNED_SHORT,0);j.disable(j.STENCIL_TEST);j.enable(j.DEPTH_TEST);j.depthMask(N)}function B(b,e){var c,f,g;c=P.attributes;var h=P.uniforms,k=U/V,m,o=[],t=V*0.5,n=U*0.5,p=!0;j.useProgram(P.program);T=P.program;aa=-1;Ba||(j.enableVertexAttribArray(P.attributes.position),j.enableVertexAttribArray(P.attributes.uv),Ba=!0);j.disable(j.CULL_FACE);j.enable(j.BLEND);j.depthMask(!0);j.bindBuffer(j.ARRAY_BUFFER,P.vertexBuffer);j.vertexAttribPointer(c.position,2,j.FLOAT,!1,16,
M
Mr.doob 已提交
249
0);j.vertexAttribPointer(c.uv,2,j.FLOAT,!1,16,8);j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,P.elementBuffer);j.uniformMatrix4fv(h.projectionMatrix,!1,ka);j.activeTexture(j.TEXTURE0);j.uniform1i(h.map,0);c=0;for(f=b.__webglSprites.length;c<f;c++)g=b.__webglSprites[c],g.useScreenCoordinates?g.z=-g.position.z:(g._modelViewMatrix.multiplyToArray(e.matrixWorldInverse,g.matrixWorld,g._modelViewMatrixArray),g.z=-g._modelViewMatrix.n34);b.__webglSprites.sort(u);c=0;for(f=b.__webglSprites.length;c<f;c++)g=b.__webglSprites[c],
250 251 252 253
g.material===void 0&&g.map&&g.map.image&&g.map.image.width&&(g.useScreenCoordinates?(j.uniform1i(h.useScreenCoordinates,1),j.uniform3f(h.screenPosition,(g.position.x-t)/t,(n-g.position.y)/n,Math.max(0,Math.min(1,g.position.z)))):(j.uniform1i(h.useScreenCoordinates,0),j.uniform1i(h.affectedByDistance,g.affectedByDistance?1:0),j.uniformMatrix4fv(h.modelViewMatrix,!1,g._modelViewMatrixArray)),m=g.map.image.width/(g.scaleByViewport?U:1),o[0]=m*k*g.scale.x,o[1]=m*g.scale.y,j.uniform2f(h.uvScale,g.uvScale.x,
g.uvScale.y),j.uniform2f(h.uvOffset,g.uvOffset.x,g.uvOffset.y),j.uniform2f(h.alignment,g.alignment.x,g.alignment.y),j.uniform1f(h.opacity,g.opacity),j.uniform1f(h.rotation,g.rotation),j.uniform2fv(h.scale,o),g.mergeWith3D&&!p?(j.enable(j.DEPTH_TEST),p=!0):!g.mergeWith3D&&p&&(j.disable(j.DEPTH_TEST),p=!1),D(g.blending),J(g.map,0),j.drawElements(j.TRIANGLES,6,j.UNSIGNED_SHORT,0));j.enable(j.CULL_FACE);j.enable(j.DEPTH_TEST);j.depthMask(N)}function A(b,e){var c,f,g=b.__webglLensFlares.length,h,k,m,o=
new THREE.Vector3,t=U/V,n=V*0.5,p=U*0.5,u=16/U,v=[u*t,u],w=[1,1,0],y=[1,1],A=O.uniforms;c=O.attributes;j.useProgram(O.program);T=O.program;aa=-1;oa||(j.enableVertexAttribArray(O.attributes.vertex),j.enableVertexAttribArray(O.attributes.uv),oa=!0);j.uniform1i(A.occlusionMap,0);j.uniform1i(A.map,1);j.bindBuffer(j.ARRAY_BUFFER,O.vertexBuffer);j.vertexAttribPointer(c.vertex,2,j.FLOAT,!1,16,0);j.vertexAttribPointer(c.uv,2,j.FLOAT,!1,16,8);j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,O.elementBuffer);j.disable(j.CULL_FACE);
j.depthMask(!1);j.activeTexture(j.TEXTURE0);j.bindTexture(j.TEXTURE_2D,O.occlusionTexture);j.activeTexture(j.TEXTURE1);for(f=0;f<g;f++)if(c=b.__webglLensFlares[f].object,o.set(c.matrixWorld.n14,c.matrixWorld.n24,c.matrixWorld.n34),e.matrixWorldInverse.multiplyVector3(o),e.projectionMatrix.multiplyVector3(o),w[0]=o.x,w[1]=o.y,w[2]=o.z,y[0]=w[0]*n+n,y[1]=w[1]*p+p,O.hasVertexTexture||y[0]>0&&y[0]<V&&y[1]>0&&y[1]<U){j.bindTexture(j.TEXTURE_2D,O.tempTexture);j.copyTexImage2D(j.TEXTURE_2D,0,j.RGB,y[0]-
M
Mr.doob 已提交
254
8,y[1]-8,16,16,0);j.uniform1i(A.renderType,0);j.uniform2fv(A.scale,v);j.uniform3fv(A.screenPosition,w);j.disable(j.BLEND);j.enable(j.DEPTH_TEST);j.drawElements(j.TRIANGLES,6,j.UNSIGNED_SHORT,0);j.bindTexture(j.TEXTURE_2D,O.occlusionTexture);j.copyTexImage2D(j.TEXTURE_2D,0,j.RGBA,y[0]-8,y[1]-8,16,16,0);j.uniform1i(A.renderType,1);j.disable(j.DEPTH_TEST);j.bindTexture(j.TEXTURE_2D,O.tempTexture);j.drawElements(j.TRIANGLES,6,j.UNSIGNED_SHORT,0);c.positionScreen.x=w[0];c.positionScreen.y=w[1];c.positionScreen.z=
A
alteredq 已提交
255
w[2];c.customUpdateCallback?c.customUpdateCallback(c):c.updateLensFlares();j.uniform1i(A.renderType,2);j.enable(j.BLEND);h=0;for(k=c.lensFlares.length;h<k;h++)if(m=c.lensFlares[h],m.opacity>0.0010&&m.scale>0.0010)w[0]=m.x,w[1]=m.y,w[2]=m.z,u=m.size*m.scale/U,v[0]=u*t,v[1]=u,j.uniform3fv(A.screenPosition,w),j.uniform2fv(A.scale,v),j.uniform1f(A.rotation,m.rotation),j.uniform1f(A.opacity,m.opacity),D(m.blending),J(m.texture,1),j.drawElements(j.TRIANGLES,6,j.UNSIGNED_SHORT,0)}j.enable(j.CULL_FACE);j.enable(j.DEPTH_TEST);
256 257 258 259 260 261
j.depthMask(N)}function y(b,e){b._modelViewMatrix.multiplyToArray(e.matrixWorldInverse,b.matrixWorld,b._modelViewMatrixArray);THREE.Matrix4.makeInvert3x3(b._modelViewMatrix).transposeIntoArray(b._normalMatrixArray)}function G(b){var e,f,g,h;if(b instanceof THREE.Mesh){f=b.geometry;for(e in f.geometryGroups){g=f.geometryGroups[e];a:{for(var k=h=void 0,m=void 0,o=void 0,t=void 0,t=g.__materials,k=0,m=t.length;k<m;k++)if(o=t[k],o.attributes)for(h in o.attributes)if(o.attributes[h].needsUpdate){h=!0;
break a}h=!1}if(f.__dirtyVertices||f.__dirtyMorphTargets||f.__dirtyElements||f.__dirtyUvs||f.__dirtyNormals||f.__dirtyColors||f.__dirtyTangents||h)if(h=g,k=b,m=j.DYNAMIC_DRAW,h.__inittedArrays){var n=t=o=void 0,p=void 0,u=n=void 0,v=void 0,w=void 0,y=void 0,A=void 0,B=void 0,z=void 0,H=void 0,G=void 0,D=void 0,Y=void 0,C=void 0,ka=void 0,E=p=y=p=w=v=void 0,F=void 0,x=F=E=v=void 0,K=void 0,J=x=F=E=n=n=u=y=p=x=F=E=K=x=F=E=K=x=F=E=void 0,I=0,L=0,N=0,P=0,la=0,O=0,ga=0,aa=0,Q=0,M=0,R=0,F=E=0,S=h.__vertexArray,
ca=h.__uvArray,ea=h.__uv2Array,da=h.__normalArray,T=h.__tangentArray,Z=h.__colorArray,U=h.__skinVertexAArray,V=h.__skinVertexBArray,X=h.__skinIndexArray,$=h.__skinWeightArray,Da=h.__morphTargetsArrays,ia=h.__webglCustomAttributes,x=void 0,fa=h.__faceArray,ha=h.__lineArray,na=h.__needsSmoothNormals,B=h.__vertexColorType,A=h.__uvType,z=h.__normalType,ja=k.geometry,ua=ja.__dirtyVertices,ta=ja.__dirtyElements,oa=ja.__dirtyUvs,qa=ja.__dirtyNormals,Aa=ja.__dirtyTangents,va=ja.__dirtyColors,ya=ja.__dirtyMorphTargets,
xa=ja.vertices,Ba=h.faces,Za=ja.faces,Xa=ja.faceVertexUvs[0],Ya=ja.faceVertexUvs[1],Ka=ja.skinVerticesA,La=ja.skinVerticesB,Ma=ja.skinIndices,Fa=ja.skinWeights,Ia=k instanceof THREE.ShadowVolume?ja.edgeFaces:void 0,Ca=ja.morphTargets;if(ia)for(J in ia)ia[J].offset=0,ia[J].offsetSrc=0;o=0;for(t=Ba.length;o<t;o++)if(n=Ba[o],p=Za[n],Xa&&(H=Xa[n]),Ya&&(G=Ya[n]),n=p.vertexNormals,u=p.normal,v=p.vertexColors,w=p.color,y=p.vertexTangents,p instanceof THREE.Face3){if(ua)D=xa[p.a].position,Y=xa[p.b].position,
C=xa[p.c].position,S[L]=D.x,S[L+1]=D.y,S[L+2]=D.z,S[L+3]=Y.x,S[L+4]=Y.y,S[L+5]=Y.z,S[L+6]=C.x,S[L+7]=C.y,S[L+8]=C.z,L+=9;if(ia)for(J in ia)if(x=ia[J],x.__original.needsUpdate)E=x.offset,F=x.offsetSrc,x.size===1?(x.boundTo===void 0||x.boundTo==="vertices"?(x.array[E+0]=x.value[p.a],x.array[E+1]=x.value[p.b],x.array[E+2]=x.value[p.c]):x.boundTo==="faces"?(x.array[E+0]=x.value[F],x.array[E+1]=x.value[F],x.array[E+2]=x.value[F],x.offsetSrc++):x.boundTo==="faceVertices"&&(x.array[E+0]=x.value[F+0],x.array[E+
1]=x.value[F+1],x.array[E+2]=x.value[F+2],x.offsetSrc+=3),x.offset+=3):(x.boundTo===void 0||x.boundTo==="vertices"?(D=x.value[p.a],Y=x.value[p.b],C=x.value[p.c]):x.boundTo==="faces"?(D=x.value[F],Y=x.value[F],C=x.value[F],x.offsetSrc++):x.boundTo==="faceVertices"&&(D=x.value[F+0],Y=x.value[F+1],C=x.value[F+2],x.offsetSrc+=3),x.size===2?(x.array[E+0]=D.x,x.array[E+1]=D.y,x.array[E+2]=Y.x,x.array[E+3]=Y.y,x.array[E+4]=C.x,x.array[E+5]=C.y,x.offset+=6):x.size===3?(x.type==="c"?(x.array[E+0]=D.r,x.array[E+
M
Mr.doob 已提交
262
1]=D.g,x.array[E+2]=D.b,x.array[E+3]=Y.r,x.array[E+4]=Y.g,x.array[E+5]=Y.b,x.array[E+6]=C.r,x.array[E+7]=C.g,x.array[E+8]=C.b):(x.array[E+0]=D.x,x.array[E+1]=D.y,x.array[E+2]=D.z,x.array[E+3]=Y.x,x.array[E+4]=Y.y,x.array[E+5]=Y.z,x.array[E+6]=C.x,x.array[E+7]=C.y,x.array[E+8]=C.z),x.offset+=9):(x.array[E+0]=D.x,x.array[E+1]=D.y,x.array[E+2]=D.z,x.array[E+3]=D.w,x.array[E+4]=Y.x,x.array[E+5]=Y.y,x.array[E+6]=Y.z,x.array[E+7]=Y.w,x.array[E+8]=C.x,x.array[E+9]=C.y,x.array[E+10]=C.z,x.array[E+11]=C.w,
263 264 265 266 267 268
x.offset+=12));if(ya){E=0;for(F=Ca.length;E<F;E++)D=Ca[E].vertices[p.a].position,Y=Ca[E].vertices[p.b].position,C=Ca[E].vertices[p.c].position,x=Da[E],x[R+0]=D.x,x[R+1]=D.y,x[R+2]=D.z,x[R+3]=Y.x,x[R+4]=Y.y,x[R+5]=Y.z,x[R+6]=C.x,x[R+7]=C.y,x[R+8]=C.z;R+=9}if(Fa.length)E=Fa[p.a],F=Fa[p.b],x=Fa[p.c],$[M]=E.x,$[M+1]=E.y,$[M+2]=E.z,$[M+3]=E.w,$[M+4]=F.x,$[M+5]=F.y,$[M+6]=F.z,$[M+7]=F.w,$[M+8]=x.x,$[M+9]=x.y,$[M+10]=x.z,$[M+11]=x.w,E=Ma[p.a],F=Ma[p.b],x=Ma[p.c],X[M]=E.x,X[M+1]=E.y,X[M+2]=E.z,X[M+3]=E.w,
X[M+4]=F.x,X[M+5]=F.y,X[M+6]=F.z,X[M+7]=F.w,X[M+8]=x.x,X[M+9]=x.y,X[M+10]=x.z,X[M+11]=x.w,E=Ka[p.a],F=Ka[p.b],x=Ka[p.c],U[M]=E.x,U[M+1]=E.y,U[M+2]=E.z,U[M+3]=1,U[M+4]=F.x,U[M+5]=F.y,U[M+6]=F.z,U[M+7]=1,U[M+8]=x.x,U[M+9]=x.y,U[M+10]=x.z,U[M+11]=1,E=La[p.a],F=La[p.b],x=La[p.c],V[M]=E.x,V[M+1]=E.y,V[M+2]=E.z,V[M+3]=1,V[M+4]=F.x,V[M+5]=F.y,V[M+6]=F.z,V[M+7]=1,V[M+8]=x.x,V[M+9]=x.y,V[M+10]=x.z,V[M+11]=1,M+=12;if(va&&B)v.length==3&&B==THREE.VertexColors?(p=v[0],E=v[1],F=v[2]):F=E=p=w,Z[Q]=p.r,Z[Q+1]=p.g,
Z[Q+2]=p.b,Z[Q+3]=E.r,Z[Q+4]=E.g,Z[Q+5]=E.b,Z[Q+6]=F.r,Z[Q+7]=F.g,Z[Q+8]=F.b,Q+=9;if(Aa&&ja.hasTangents)v=y[0],w=y[1],p=y[2],T[ga]=v.x,T[ga+1]=v.y,T[ga+2]=v.z,T[ga+3]=v.w,T[ga+4]=w.x,T[ga+5]=w.y,T[ga+6]=w.z,T[ga+7]=w.w,T[ga+8]=p.x,T[ga+9]=p.y,T[ga+10]=p.z,T[ga+11]=p.w,ga+=12;if(qa&&z)if(n.length==3&&na)for(y=0;y<3;y++)u=n[y],da[O]=u.x,da[O+1]=u.y,da[O+2]=u.z,O+=3;else for(y=0;y<3;y++)da[O]=u.x,da[O+1]=u.y,da[O+2]=u.z,O+=3;if(oa&&H!==void 0&&A)for(y=0;y<3;y++)n=H[y],ca[N]=n.u,ca[N+1]=n.v,N+=2;if(oa&&
G!==void 0&&A)for(y=0;y<3;y++)n=G[y],ea[P]=n.u,ea[P+1]=n.v,P+=2;ta&&(fa[la]=I,fa[la+1]=I+1,fa[la+2]=I+2,la+=3,ha[aa]=I,ha[aa+1]=I+1,ha[aa+2]=I,ha[aa+3]=I+2,ha[aa+4]=I+1,ha[aa+5]=I+2,aa+=6,I+=3)}else if(p instanceof THREE.Face4){if(ua)D=xa[p.a].position,Y=xa[p.b].position,C=xa[p.c].position,ka=xa[p.d].position,S[L]=D.x,S[L+1]=D.y,S[L+2]=D.z,S[L+3]=Y.x,S[L+4]=Y.y,S[L+5]=Y.z,S[L+6]=C.x,S[L+7]=C.y,S[L+8]=C.z,S[L+9]=ka.x,S[L+10]=ka.y,S[L+11]=ka.z,L+=12;if(ia)for(J in ia)if(x=ia[J],x.__original.needsUpdate)E=
x.offset,F=x.offsetSrc,x.size===1?(x.boundTo===void 0||x.boundTo==="vertices"?(x.array[E+0]=x.value[p.a],x.array[E+1]=x.value[p.b],x.array[E+2]=x.value[p.c],x.array[E+3]=x.value[p.d]):x.boundTo==="faces"?(x.array[E+0]=x.value[F],x.array[E+1]=x.value[F],x.array[E+2]=x.value[F],x.array[E+3]=x.value[F],x.offsetSrc++):x.boundTo==="faceVertices"&&(x.array[E+0]=x.value[F+0],x.array[E+1]=x.value[F+1],x.array[E+2]=x.value[F+2],x.array[E+3]=x.value[F+3],x.offsetSrc+=4),x.offset+=4):(x.boundTo===void 0||x.boundTo===
"vertices"?(D=x.value[p.a],Y=x.value[p.b],C=x.value[p.c],ka=x.value[p.d]):x.boundTo==="faces"?(D=x.value[F],Y=x.value[F],C=x.value[F],ka=x.value[F],x.offsetSrc++):x.boundTo==="faceVertices"&&(D=x.value[F+0],Y=x.value[F+1],C=x.value[F+2],ka=x.value[F+3],x.offsetSrc+=4),x.size===2?(x.array[E+0]=D.x,x.array[E+1]=D.y,x.array[E+2]=Y.x,x.array[E+3]=Y.y,x.array[E+4]=C.x,x.array[E+5]=C.y,x.array[E+6]=ka.x,x.array[E+7]=ka.y,x.offset+=8):x.size===3?(x.type==="c"?(x.array[E+0]=D.r,x.array[E+1]=D.g,x.array[E+
M
Mr.doob 已提交
269
2]=D.b,x.array[E+3]=Y.r,x.array[E+4]=Y.g,x.array[E+5]=Y.b,x.array[E+6]=C.r,x.array[E+7]=C.g,x.array[E+8]=C.b,x.array[E+9]=ka.r,x.array[E+10]=ka.g,x.array[E+11]=ka.b):(x.array[E+0]=D.x,x.array[E+1]=D.y,x.array[E+2]=D.z,x.array[E+3]=Y.x,x.array[E+4]=Y.y,x.array[E+5]=Y.z,x.array[E+6]=C.x,x.array[E+7]=C.y,x.array[E+8]=C.z,x.array[E+9]=ka.x,x.array[E+10]=ka.y,x.array[E+11]=ka.z),x.offset+=12):(x.array[E+0]=D.x,x.array[E+1]=D.y,x.array[E+2]=D.z,x.array[E+3]=D.w,x.array[E+4]=Y.x,x.array[E+5]=Y.y,x.array[E+
270 271 272 273 274
6]=Y.z,x.array[E+7]=Y.w,x.array[E+8]=C.x,x.array[E+9]=C.y,x.array[E+10]=C.z,x.array[E+11]=C.w,x.array[E+12]=ka.x,x.array[E+13]=ka.y,x.array[E+14]=ka.z,x.array[E+15]=ka.w,x.offset+=16));if(ya){E=0;for(F=Ca.length;E<F;E++)D=Ca[E].vertices[p.a].position,Y=Ca[E].vertices[p.b].position,C=Ca[E].vertices[p.c].position,ka=Ca[E].vertices[p.d].position,x=Da[E],x[R+0]=D.x,x[R+1]=D.y,x[R+2]=D.z,x[R+3]=Y.x,x[R+4]=Y.y,x[R+5]=Y.z,x[R+6]=C.x,x[R+7]=C.y,x[R+8]=C.z,x[R+9]=ka.x,x[R+10]=ka.y,x[R+11]=ka.z;R+=12}if(Fa.length)E=
Fa[p.a],F=Fa[p.b],x=Fa[p.c],K=Fa[p.d],$[M]=E.x,$[M+1]=E.y,$[M+2]=E.z,$[M+3]=E.w,$[M+4]=F.x,$[M+5]=F.y,$[M+6]=F.z,$[M+7]=F.w,$[M+8]=x.x,$[M+9]=x.y,$[M+10]=x.z,$[M+11]=x.w,$[M+12]=K.x,$[M+13]=K.y,$[M+14]=K.z,$[M+15]=K.w,E=Ma[p.a],F=Ma[p.b],x=Ma[p.c],K=Ma[p.d],X[M]=E.x,X[M+1]=E.y,X[M+2]=E.z,X[M+3]=E.w,X[M+4]=F.x,X[M+5]=F.y,X[M+6]=F.z,X[M+7]=F.w,X[M+8]=x.x,X[M+9]=x.y,X[M+10]=x.z,X[M+11]=x.w,X[M+12]=K.x,X[M+13]=K.y,X[M+14]=K.z,X[M+15]=K.w,E=Ka[p.a],F=Ka[p.b],x=Ka[p.c],K=Ka[p.d],U[M]=E.x,U[M+1]=E.y,U[M+
2]=E.z,U[M+3]=1,U[M+4]=F.x,U[M+5]=F.y,U[M+6]=F.z,U[M+7]=1,U[M+8]=x.x,U[M+9]=x.y,U[M+10]=x.z,U[M+11]=1,U[M+12]=K.x,U[M+13]=K.y,U[M+14]=K.z,U[M+15]=1,E=La[p.a],F=La[p.b],x=La[p.c],p=La[p.d],V[M]=E.x,V[M+1]=E.y,V[M+2]=E.z,V[M+3]=1,V[M+4]=F.x,V[M+5]=F.y,V[M+6]=F.z,V[M+7]=1,V[M+8]=x.x,V[M+9]=x.y,V[M+10]=x.z,V[M+11]=1,V[M+12]=p.x,V[M+13]=p.y,V[M+14]=p.z,V[M+15]=1,M+=16;if(va&&B)v.length==4&&B==THREE.VertexColors?(p=v[0],E=v[1],F=v[2],v=v[3]):v=F=E=p=w,Z[Q]=p.r,Z[Q+1]=p.g,Z[Q+2]=p.b,Z[Q+3]=E.r,Z[Q+4]=E.g,
Z[Q+5]=E.b,Z[Q+6]=F.r,Z[Q+7]=F.g,Z[Q+8]=F.b,Z[Q+9]=v.r,Z[Q+10]=v.g,Z[Q+11]=v.b,Q+=12;if(Aa&&ja.hasTangents)v=y[0],w=y[1],p=y[2],y=y[3],T[ga]=v.x,T[ga+1]=v.y,T[ga+2]=v.z,T[ga+3]=v.w,T[ga+4]=w.x,T[ga+5]=w.y,T[ga+6]=w.z,T[ga+7]=w.w,T[ga+8]=p.x,T[ga+9]=p.y,T[ga+10]=p.z,T[ga+11]=p.w,T[ga+12]=y.x,T[ga+13]=y.y,T[ga+14]=y.z,T[ga+15]=y.w,ga+=16;if(qa&&z)if(n.length==4&&na)for(y=0;y<4;y++)u=n[y],da[O]=u.x,da[O+1]=u.y,da[O+2]=u.z,O+=3;else for(y=0;y<4;y++)da[O]=u.x,da[O+1]=u.y,da[O+2]=u.z,O+=3;if(oa&&H!==void 0&&
A)for(y=0;y<4;y++)n=H[y],ca[N]=n.u,ca[N+1]=n.v,N+=2;if(oa&&G!==void 0&&A)for(y=0;y<4;y++)n=G[y],ea[P]=n.u,ea[P+1]=n.v,P+=2;ta&&(fa[la]=I,fa[la+1]=I+1,fa[la+2]=I+3,fa[la+3]=I+1,fa[la+4]=I+2,fa[la+5]=I+3,la+=6,ha[aa]=I,ha[aa+1]=I+1,ha[aa+2]=I,ha[aa+3]=I+3,ha[aa+4]=I+1,ha[aa+5]=I+2,ha[aa+6]=I+2,ha[aa+7]=I+3,aa+=8,I+=4)}if(Ia){o=0;for(t=Ia.length;o<t;o++)fa[la]=Ia[o].a,fa[la+1]=Ia[o].b,fa[la+2]=Ia[o].c,fa[la+3]=Ia[o].a,fa[la+4]=Ia[o].c,fa[la+5]=Ia[o].d,la+=6}ua&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglVertexBuffer),
M
Mr.doob 已提交
275 276
j.bufferData(j.ARRAY_BUFFER,S,m));if(ia)for(J in ia)x=ia[J],x.__original.needsUpdate&&(j.bindBuffer(j.ARRAY_BUFFER,x.buffer),j.bufferData(j.ARRAY_BUFFER,x.array,m));if(ya){E=0;for(F=Ca.length;E<F;E++)j.bindBuffer(j.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[E]),j.bufferData(j.ARRAY_BUFFER,Da[E],m)}va&&Q>0&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglColorBuffer),j.bufferData(j.ARRAY_BUFFER,Z,m));qa&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglNormalBuffer),j.bufferData(j.ARRAY_BUFFER,da,m));Aa&&ja.hasTangents&&
(j.bindBuffer(j.ARRAY_BUFFER,h.__webglTangentBuffer),j.bufferData(j.ARRAY_BUFFER,T,m));oa&&N>0&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglUVBuffer),j.bufferData(j.ARRAY_BUFFER,ca,m));oa&&P>0&&(j.bindBuffer(j.ARRAY_BUFFER,h.__webglUV2Buffer),j.bufferData(j.ARRAY_BUFFER,ea,m));ta&&(j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,h.__webglFaceBuffer),j.bufferData(j.ELEMENT_ARRAY_BUFFER,fa,m),j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,h.__webglLineBuffer),j.bufferData(j.ELEMENT_ARRAY_BUFFER,ha,m));M>0&&(j.bindBuffer(j.ARRAY_BUFFER,
277
h.__webglSkinVertexABuffer),j.bufferData(j.ARRAY_BUFFER,U,m),j.bindBuffer(j.ARRAY_BUFFER,h.__webglSkinVertexBBuffer),j.bufferData(j.ARRAY_BUFFER,V,m),j.bindBuffer(j.ARRAY_BUFFER,h.__webglSkinIndicesBuffer),j.bufferData(j.ARRAY_BUFFER,X,m),j.bindBuffer(j.ARRAY_BUFFER,h.__webglSkinWeightsBuffer),j.bufferData(j.ARRAY_BUFFER,$,m));k.dynamic||(delete h.__inittedArrays,delete h.__colorArray,delete h.__normalArray,delete h.__tangentArray,delete h.__uvArray,delete h.__uv2Array,delete h.__faceArray,delete h.__vertexArray,
M
Mr.doob 已提交
278
delete h.__lineArray,delete h.__skinVertexAArray,delete h.__skinVertexBArray,delete h.__skinIndexArray,delete h.__skinWeightArray)}}f.__dirtyVertices=!1;f.__dirtyMorphTargets=!1;f.__dirtyElements=!1;f.__dirtyUvs=!1;f.__dirtyNormals=!1;f.__dirtyTangents=!1;f.__dirtyColors=!1;var sa;g=g.__materials;f=0;for(b=g.length;f<b;f++)if(e=g[f],e.attributes)for(sa in e.attributes)e.attributes[sa].needsUpdate=!1}else if(b instanceof THREE.Ribbon){f=b.geometry;if(f.__dirtyVertices||f.__dirtyColors){sa=f;b=j.DYNAMIC_DRAW;
279 280 281 282
t=sa.vertices;g=sa.colors;A=t.length;h=g.length;B=sa.__vertexArray;k=sa.__colorArray;z=sa.__dirtyColors;if(sa.__dirtyVertices){for(m=0;m<A;m++)o=t[m].position,e=m*3,B[e]=o.x,B[e+1]=o.y,B[e+2]=o.z;j.bindBuffer(j.ARRAY_BUFFER,sa.__webglVertexBuffer);j.bufferData(j.ARRAY_BUFFER,B,b)}if(z){for(m=0;m<h;m++)color=g[m],e=m*3,k[e]=color.r,k[e+1]=color.g,k[e+2]=color.b;j.bindBuffer(j.ARRAY_BUFFER,sa.__webglColorBuffer);j.bufferData(j.ARRAY_BUFFER,k,b)}}f.__dirtyVertices=!1;f.__dirtyColors=!1}else if(b instanceof
THREE.Line){f=b.geometry;if(f.__dirtyVertices||f.__dirtyColors){sa=f;b=j.DYNAMIC_DRAW;t=sa.vertices;g=sa.colors;A=t.length;h=g.length;B=sa.__vertexArray;k=sa.__colorArray;z=sa.__dirtyColors;if(sa.__dirtyVertices){for(m=0;m<A;m++)o=t[m].position,e=m*3,B[e]=o.x,B[e+1]=o.y,B[e+2]=o.z;j.bindBuffer(j.ARRAY_BUFFER,sa.__webglVertexBuffer);j.bufferData(j.ARRAY_BUFFER,B,b)}if(z){for(m=0;m<h;m++)color=g[m],e=m*3,k[e]=color.r,k[e+1]=color.g,k[e+2]=color.b;j.bindBuffer(j.ARRAY_BUFFER,sa.__webglColorBuffer);j.bufferData(j.ARRAY_BUFFER,
k,b)}}f.__dirtyVertices=!1;f.__dirtyColors=!1}else if(b instanceof THREE.ParticleSystem)f=b.geometry,(f.__dirtyVertices||f.__dirtyColors||b.sortParticles)&&c(f,j.DYNAMIC_DRAW,b),f.__dirtyVertices=!1,f.__dirtyColors=!1}function z(b,e){var c;for(c=b.length-1;c>=0;c--)b[c].object==e&&b.splice(c,1)}function C(b){function e(b){var h=[];c=0;for(f=b.length;c<f;c++)b[c]==void 0?h.push("undefined"):h.push(b[c].id);return h.join("_")}var c,f,h,g,j,k,m,o,p={},n=b.morphTargets!==void 0?b.morphTargets.length:
0;b.geometryGroups={};h=0;for(g=b.faces.length;h<g;h++)j=b.faces[h],k=j.materials,m=e(k),p[m]==void 0&&(p[m]={hash:m,counter:0}),o=p[m].hash+"_"+p[m].counter,b.geometryGroups[o]==void 0&&(b.geometryGroups[o]={faces:[],materials:k,vertices:0,numMorphTargets:n}),j=j instanceof THREE.Face3?3:4,b.geometryGroups[o].vertices+j>65535&&(p[m].counter+=1,o=p[m].hash+"_"+p[m].counter,b.geometryGroups[o]==void 0&&(b.geometryGroups[o]={faces:[],materials:k,vertices:0,numMorphTargets:n})),b.geometryGroups[o].faces.push(h),
M
Mr.doob 已提交
283
b.geometryGroups[o].vertices+=j}function H(b,e,c){b.push({buffer:e,object:c,opaque:{list:[],count:0},transparent:{list:[],count:0}})}function D(b){if(b!=aa){switch(b){case THREE.AdditiveBlending:j.blendEquation(j.FUNC_ADD);j.blendFunc(j.SRC_ALPHA,j.ONE);break;case THREE.SubtractiveBlending:j.blendEquation(j.FUNC_ADD);j.blendFunc(j.ZERO,j.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:j.blendEquation(j.FUNC_ADD);j.blendFunc(j.ZERO,j.SRC_COLOR);break;default:j.blendEquationSeparate(j.FUNC_ADD,
M
Mr.doob 已提交
284
j.FUNC_ADD),j.blendFuncSeparate(j.SRC_ALPHA,j.ONE_MINUS_SRC_ALPHA,j.ONE,j.ONE_MINUS_SRC_ALPHA)}aa=b}}function Q(b,e,c){(c.width&c.width-1)==0&&(c.height&c.height-1)==0?(j.texParameteri(b,j.TEXTURE_WRAP_S,K(e.wrapS)),j.texParameteri(b,j.TEXTURE_WRAP_T,K(e.wrapT)),j.texParameteri(b,j.TEXTURE_MAG_FILTER,K(e.magFilter)),j.texParameteri(b,j.TEXTURE_MIN_FILTER,K(e.minFilter)),j.generateMipmap(b)):(j.texParameteri(b,j.TEXTURE_WRAP_S,j.CLAMP_TO_EDGE),j.texParameteri(b,j.TEXTURE_WRAP_T,j.CLAMP_TO_EDGE),j.texParameteri(b,
M
Mr.doob 已提交
285
j.TEXTURE_MAG_FILTER,S(e.magFilter)),j.texParameteri(b,j.TEXTURE_MIN_FILTER,S(e.minFilter)))}function J(b,e){if(b.needsUpdate)b.__webglInit?(j.bindTexture(j.TEXTURE_2D,b.__webglTexture),j.texImage2D(j.TEXTURE_2D,0,j.RGBA,j.RGBA,j.UNSIGNED_BYTE,b.image)):(b.__webglTexture=j.createTexture(),j.bindTexture(j.TEXTURE_2D,b.__webglTexture),j.texImage2D(j.TEXTURE_2D,0,j.RGBA,j.RGBA,j.UNSIGNED_BYTE,b.image),b.__webglInit=!0),Q(j.TEXTURE_2D,b,b.image),j.bindTexture(j.TEXTURE_2D,null),b.needsUpdate=!1;j.activeTexture(j.TEXTURE0+
M
Mr.doob 已提交
286 287 288
e);j.bindTexture(j.TEXTURE_2D,b.__webglTexture)}function F(b){if(b&&!b.__webglFramebuffer){if(b.depthBuffer===void 0)b.depthBuffer=!0;if(b.stencilBuffer===void 0)b.stencilBuffer=!0;b.__webglFramebuffer=j.createFramebuffer();b.__webglRenderbuffer=j.createRenderbuffer();b.__webglTexture=j.createTexture();j.bindTexture(j.TEXTURE_2D,b.__webglTexture);j.texParameteri(j.TEXTURE_2D,j.TEXTURE_WRAP_S,K(b.wrapS));j.texParameteri(j.TEXTURE_2D,j.TEXTURE_WRAP_T,K(b.wrapT));j.texParameteri(j.TEXTURE_2D,j.TEXTURE_MAG_FILTER,
K(b.magFilter));j.texParameteri(j.TEXTURE_2D,j.TEXTURE_MIN_FILTER,K(b.minFilter));j.texImage2D(j.TEXTURE_2D,0,K(b.format),b.width,b.height,0,K(b.format),K(b.type),null);j.bindRenderbuffer(j.RENDERBUFFER,b.__webglRenderbuffer);j.bindFramebuffer(j.FRAMEBUFFER,b.__webglFramebuffer);j.framebufferTexture2D(j.FRAMEBUFFER,j.COLOR_ATTACHMENT0,j.TEXTURE_2D,b.__webglTexture,0);b.depthBuffer&&!b.stencilBuffer?(j.renderbufferStorage(j.RENDERBUFFER,j.DEPTH_COMPONENT16,b.width,b.height),j.framebufferRenderbuffer(j.FRAMEBUFFER,
j.DEPTH_ATTACHMENT,j.RENDERBUFFER,b.__webglRenderbuffer)):b.depthBuffer&&b.stencilBuffer?(j.renderbufferStorage(j.RENDERBUFFER,j.DEPTH_STENCIL,b.width,b.height),j.framebufferRenderbuffer(j.FRAMEBUFFER,j.DEPTH_STENCIL_ATTACHMENT,j.RENDERBUFFER,b.__webglRenderbuffer)):j.renderbufferStorage(j.RENDERBUFFER,j.RGBA4,b.width,b.height);j.bindTexture(j.TEXTURE_2D,null);j.bindRenderbuffer(j.RENDERBUFFER,null);j.bindFramebuffer(j.FRAMEBUFFER,null)}var e,c;b?(e=b.__webglFramebuffer,c=b.width,b=b.height):(e=null,
289
c=V,b=U);e!=Z&&(j.bindFramebuffer(j.FRAMEBUFFER,e),j.viewport(L,fa,c,b),Z=e)}function I(b,e){var c;b=="fragment"?c=j.createShader(j.FRAGMENT_SHADER):b=="vertex"&&(c=j.createShader(j.VERTEX_SHADER));j.shaderSource(c,e);j.compileShader(c);if(!j.getShaderParameter(c,j.COMPILE_STATUS))return console.error(j.getShaderInfoLog(c)),console.error(e),null;return c}function S(b){switch(b){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return j.NEAREST;default:return j.LINEAR}}
M
Mr.doob 已提交
290 291
function K(b){switch(b){case THREE.RepeatWrapping:return j.REPEAT;case THREE.ClampToEdgeWrapping:return j.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return j.MIRRORED_REPEAT;case THREE.NearestFilter:return j.NEAREST;case THREE.NearestMipMapNearestFilter:return j.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return j.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return j.LINEAR;case THREE.LinearMipMapNearestFilter:return j.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return j.LINEAR_MIPMAP_LINEAR;
case THREE.ByteType:return j.BYTE;case THREE.UnsignedByteType:return j.UNSIGNED_BYTE;case THREE.ShortType:return j.SHORT;case THREE.UnsignedShortType:return j.UNSIGNED_SHORT;case THREE.IntType:return j.INT;case THREE.UnsignedShortType:return j.UNSIGNED_INT;case THREE.FloatType:return j.FLOAT;case THREE.AlphaFormat:return j.ALPHA;case THREE.RGBFormat:return j.RGB;case THREE.RGBAFormat:return j.RGBA;case THREE.LuminanceFormat:return j.LUMINANCE;case THREE.LuminanceAlphaFormat:return j.LUMINANCE_ALPHA}return 0}
292
var ea=this,j,ca=[],T=null,Z=null,N=!0,da=null,X=null,aa=null,ia=null,ha=null,na=null,ja=null,L=0,fa=0,V=0,U=0,$=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],Y=new THREE.Matrix4,ka=new Float32Array(16),la=new Float32Array(16),ga=new THREE.Vector4,Da={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]}},b=b||{},ua=b.canvas!==void 0?b.canvas:document.createElement("canvas"),
M
Mr.doob 已提交
293 294 295
Aa=b.stencil!==void 0?b.stencil:!0,xa=b.antialias!==void 0?b.antialias:!1,ta=b.clearColor!==void 0?new THREE.Color(b.clearColor):new THREE.Color(0),ya=b.clearAlpha!==void 0?b.clearAlpha:0;this.data={vertices:0,faces:0,drawCalls:0};this.maxMorphTargets=8;this.domElement=ua;this.sortObjects=this.autoClear=!0;try{if(!(j=ua.getContext("experimental-webgl",{antialias:xa,stencil:Aa})))throw"Error creating WebGL context.";console.log(navigator.userAgent+" | "+j.getParameter(j.VERSION)+" | "+j.getParameter(j.VENDOR)+
" | "+j.getParameter(j.RENDERER)+" | "+j.getParameter(j.SHADING_LANGUAGE_VERSION))}catch(va){console.error(va)}j.clearColor(0,0,0,1);j.clearDepth(1);j.enable(j.DEPTH_TEST);j.depthFunc(j.LEQUAL);j.frontFace(j.CCW);j.cullFace(j.BACK);j.enable(j.CULL_FACE);j.enable(j.BLEND);j.blendEquation(j.FUNC_ADD);j.blendFunc(j.SRC_ALPHA,j.ONE_MINUS_SRC_ALPHA);j.clearColor(ta.r,ta.g,ta.b,ya);this.context=j;var qa=j.getParameter(j.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0;if(Aa){var R={};R.vertices=new Float32Array(12);R.faces=
new Uint16Array(6);R.darkness=0.5;R.vertices[0]=-20;R.vertices[1]=-20;R.vertices[2]=-1;R.vertices[3]=20;R.vertices[4]=-20;R.vertices[5]=-1;R.vertices[6]=20;R.vertices[7]=20;R.vertices[8]=-1;R.vertices[9]=-20;R.vertices[10]=20;R.vertices[11]=-1;R.faces[0]=0;R.faces[1]=1;R.faces[2]=2;R.faces[3]=0;R.faces[4]=2;R.faces[5]=3;R.vertexBuffer=j.createBuffer();R.elementBuffer=j.createBuffer();j.bindBuffer(j.ARRAY_BUFFER,R.vertexBuffer);j.bufferData(j.ARRAY_BUFFER,R.vertices,j.STATIC_DRAW);j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,
M
Mr.doob 已提交
296 297 298 299 300 301 302 303 304 305
R.elementBuffer);j.bufferData(j.ELEMENT_ARRAY_BUFFER,R.faces,j.STATIC_DRAW);R.program=j.createProgram();j.attachShader(R.program,I("fragment",THREE.ShaderLib.shadowPost.fragmentShader));j.attachShader(R.program,I("vertex",THREE.ShaderLib.shadowPost.vertexShader));j.linkProgram(R.program);R.vertexLocation=j.getAttribLocation(R.program,"position");R.projectionLocation=j.getUniformLocation(R.program,"projectionMatrix");R.darknessLocation=j.getUniformLocation(R.program,"darkness")}var O={};O.vertices=
new Float32Array(16);O.faces=new Uint16Array(6);b=0;O.vertices[b++]=-1;O.vertices[b++]=-1;O.vertices[b++]=0;O.vertices[b++]=0;O.vertices[b++]=1;O.vertices[b++]=-1;O.vertices[b++]=1;O.vertices[b++]=0;O.vertices[b++]=1;O.vertices[b++]=1;O.vertices[b++]=1;O.vertices[b++]=1;O.vertices[b++]=-1;O.vertices[b++]=1;O.vertices[b++]=0;O.vertices[b++]=1;b=0;O.faces[b++]=0;O.faces[b++]=1;O.faces[b++]=2;O.faces[b++]=0;O.faces[b++]=2;O.faces[b++]=3;O.vertexBuffer=j.createBuffer();O.elementBuffer=j.createBuffer();
O.tempTexture=j.createTexture();O.occlusionTexture=j.createTexture();j.bindBuffer(j.ARRAY_BUFFER,O.vertexBuffer);j.bufferData(j.ARRAY_BUFFER,O.vertices,j.STATIC_DRAW);j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,O.elementBuffer);j.bufferData(j.ELEMENT_ARRAY_BUFFER,O.faces,j.STATIC_DRAW);j.bindTexture(j.TEXTURE_2D,O.tempTexture);j.texImage2D(j.TEXTURE_2D,0,j.RGB,16,16,0,j.RGB,j.UNSIGNED_BYTE,null);j.texParameteri(j.TEXTURE_2D,j.TEXTURE_WRAP_S,j.CLAMP_TO_EDGE);j.texParameteri(j.TEXTURE_2D,j.TEXTURE_WRAP_T,j.CLAMP_TO_EDGE);
j.texParameteri(j.TEXTURE_2D,j.TEXTURE_MAG_FILTER,j.NEAREST);j.texParameteri(j.TEXTURE_2D,j.TEXTURE_MIN_FILTER,j.NEAREST);j.bindTexture(j.TEXTURE_2D,O.occlusionTexture);j.texImage2D(j.TEXTURE_2D,0,j.RGBA,16,16,0,j.RGBA,j.UNSIGNED_BYTE,null);j.texParameteri(j.TEXTURE_2D,j.TEXTURE_WRAP_S,j.CLAMP_TO_EDGE);j.texParameteri(j.TEXTURE_2D,j.TEXTURE_WRAP_T,j.CLAMP_TO_EDGE);j.texParameteri(j.TEXTURE_2D,j.TEXTURE_MAG_FILTER,j.NEAREST);j.texParameteri(j.TEXTURE_2D,j.TEXTURE_MIN_FILTER,j.NEAREST);j.getParameter(j.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=
0?(O.hasVertexTexture=!1,O.program=j.createProgram(),j.attachShader(O.program,I("fragment",THREE.ShaderLib.lensFlare.fragmentShader)),j.attachShader(O.program,I("vertex",THREE.ShaderLib.lensFlare.vertexShader))):(O.hasVertexTexture=!0,O.program=j.createProgram(),j.attachShader(O.program,I("fragment",THREE.ShaderLib.lensFlareVertexTexture.fragmentShader)),j.attachShader(O.program,I("vertex",THREE.ShaderLib.lensFlareVertexTexture.vertexShader)));j.linkProgram(O.program);O.attributes={};O.uniforms={};
O.attributes.vertex=j.getAttribLocation(O.program,"position");O.attributes.uv=j.getAttribLocation(O.program,"UV");O.uniforms.renderType=j.getUniformLocation(O.program,"renderType");O.uniforms.map=j.getUniformLocation(O.program,"map");O.uniforms.occlusionMap=j.getUniformLocation(O.program,"occlusionMap");O.uniforms.opacity=j.getUniformLocation(O.program,"opacity");O.uniforms.scale=j.getUniformLocation(O.program,"scale");O.uniforms.rotation=j.getUniformLocation(O.program,"rotation");O.uniforms.screenPosition=
j.getUniformLocation(O.program,"screenPosition");var oa=!1,P={};P.vertices=new Float32Array(16);P.faces=new Uint16Array(6);b=0;P.vertices[b++]=-1;P.vertices[b++]=-1;P.vertices[b++]=0;P.vertices[b++]=1;P.vertices[b++]=1;P.vertices[b++]=-1;P.vertices[b++]=1;P.vertices[b++]=1;P.vertices[b++]=1;P.vertices[b++]=1;P.vertices[b++]=1;P.vertices[b++]=0;P.vertices[b++]=-1;P.vertices[b++]=1;P.vertices[b++]=0;b=P.vertices[b++]=0;P.faces[b++]=0;P.faces[b++]=1;P.faces[b++]=2;P.faces[b++]=0;P.faces[b++]=2;P.faces[b++]=
3;P.vertexBuffer=j.createBuffer();P.elementBuffer=j.createBuffer();j.bindBuffer(j.ARRAY_BUFFER,P.vertexBuffer);j.bufferData(j.ARRAY_BUFFER,P.vertices,j.STATIC_DRAW);j.bindBuffer(j.ELEMENT_ARRAY_BUFFER,P.elementBuffer);j.bufferData(j.ELEMENT_ARRAY_BUFFER,P.faces,j.STATIC_DRAW);P.program=j.createProgram();j.attachShader(P.program,I("fragment",THREE.ShaderLib.sprite.fragmentShader));j.attachShader(P.program,I("vertex",THREE.ShaderLib.sprite.vertexShader));j.linkProgram(P.program);P.attributes={};P.uniforms=
{};P.attributes.position=j.getAttribLocation(P.program,"position");P.attributes.uv=j.getAttribLocation(P.program,"uv");P.uniforms.uvOffset=j.getUniformLocation(P.program,"uvOffset");P.uniforms.uvScale=j.getUniformLocation(P.program,"uvScale");P.uniforms.rotation=j.getUniformLocation(P.program,"rotation");P.uniforms.scale=j.getUniformLocation(P.program,"scale");P.uniforms.alignment=j.getUniformLocation(P.program,"alignment");P.uniforms.map=j.getUniformLocation(P.program,"map");P.uniforms.opacity=j.getUniformLocation(P.program,
"opacity");P.uniforms.useScreenCoordinates=j.getUniformLocation(P.program,"useScreenCoordinates");P.uniforms.affectedByDistance=j.getUniformLocation(P.program,"affectedByDistance");P.uniforms.screenPosition=j.getUniformLocation(P.program,"screenPosition");P.uniforms.modelViewMatrix=j.getUniformLocation(P.program,"modelViewMatrix");P.uniforms.projectionMatrix=j.getUniformLocation(P.program,"projectionMatrix");var Ba=!1;this.setSize=function(b,e){ua.width=b;ua.height=e;this.setViewport(0,0,ua.width,
306
ua.height)};this.setViewport=function(b,e,c,f){L=b;fa=e;V=c;U=f;j.viewport(L,fa,V,U)};this.setScissor=function(b,e,c,f){j.scissor(b,e,c,f)};this.enableScissorTest=function(b){b?j.enable(j.SCISSOR_TEST):j.disable(j.SCISSOR_TEST)};this.enableDepthBufferWrite=function(b){N=b;j.depthMask(b)};this.setClearColorHex=function(b,e){ta.setHex(b);ya=e;j.clearColor(ta.r,ta.g,ta.b,ya)};this.setClearColor=function(b,e){ta.copy(b);ya=e;j.clearColor(ta.r,ta.g,ta.b,ya)};this.clear=function(){j.clear(j.COLOR_BUFFER_BIT|
307
j.DEPTH_BUFFER_BIT|j.STENCIL_BUFFER_BIT)};this.setStencilShadowDarkness=function(b){R.darkness=b};this.getContext=function(){return j};this.initMaterial=function(b,e,c,f){var h,g,k;b instanceof THREE.MeshDepthMaterial?k="depth":b instanceof THREE.ShadowVolumeDynamicMaterial?k="shadowVolumeDynamic":b instanceof THREE.MeshNormalMaterial?k="normal":b instanceof THREE.MeshBasicMaterial?k="basic":b instanceof THREE.MeshLambertMaterial?k="lambert":b instanceof THREE.MeshPhongMaterial?k="phong":b instanceof
308 309
THREE.LineBasicMaterial?k="basic":b instanceof THREE.ParticleBasicMaterial&&(k="particle_basic");if(k){var m=THREE.ShaderLib[k];b.uniforms=THREE.UniformsUtils.clone(m.uniforms);b.vertexShader=m.vertexShader;b.fragmentShader=m.fragmentShader}var o,p,n;o=n=m=0;for(p=e.length;o<p;o++)g=e[o],g instanceof THREE.DirectionalLight&&n++,g instanceof THREE.PointLight&&m++;m+n<=4?e=n:(e=Math.ceil(4*n/(m+n)),m=4-e);g={directional:e,point:m};n=50;if(f!==void 0&&f instanceof THREE.SkinnedMesh)n=f.bones.length;
var t;a:{o=b.fragmentShader;p=b.vertexShader;var m=b.uniforms,e=b.attributes,c={map:!!b.map,envMap:!!b.envMap,lightMap:!!b.lightMap,vertexColors:b.vertexColors,fog:c,sizeAttenuation:b.sizeAttenuation,skinning:b.skinning,morphTargets:b.morphTargets,maxMorphTargets:this.maxMorphTargets,maxDirLights:g.directional,maxPointLights:g.point,maxBones:n},u;g=[];k?g.push(k):(g.push(o),g.push(p));for(u in c)g.push(u),g.push(c[u]);k=g.join();u=0;for(g=ca.length;u<g;u++)if(ca[u].code==k){t=ca[u].program;break a}u=
310
j.createProgram();g=[qa?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_BONES "+c.maxBones,c.map?"#define USE_MAP":"",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.skinning?"#define USE_SKINNING":"",c.morphTargets?"#define USE_MORPHTARGETS":"",c.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nuniform mat4 cameraInverseMatrix;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n");
311 312 313 314 315 316 317
n=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,c.fog?"#define USE_FOG":"",c.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",c.map?"#define USE_MAP":"",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");j.attachShader(u,I("fragment",n+o));j.attachShader(u,I("vertex",g+p));j.linkProgram(u);
j.getProgramParameter(u,j.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+j.getProgramParameter(u,j.VALIDATE_STATUS)+", gl error ["+j.getError()+"]");u.uniforms={};u.attributes={};var v;o=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","cameraInverseMatrix","boneGlobalMatrices","morphTargetInfluences"];for(v in m)o.push(v);v=o;m=0;for(o=v.length;m<o;m++)p=v[m],u.uniforms[p]=j.getUniformLocation(u,p);o=["position","normal",
"uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(v=0;v<c.maxMorphTargets;v++)o.push("morphTarget"+v);for(t in e)o.push(t);t=o;v=0;for(e=t.length;v<e;v++)c=t[v],u.attributes[c]=j.getAttribLocation(u,c);ca.push({program:u,code:k});t=u}b.program=t;t=b.program.attributes;t.position>=0&&j.enableVertexAttribArray(t.position);t.color>=0&&j.enableVertexAttribArray(t.color);t.normal>=0&&j.enableVertexAttribArray(t.normal);t.tangent>=0&&j.enableVertexAttribArray(t.tangent);
b.skinning&&t.skinVertexA>=0&&t.skinVertexB>=0&&t.skinIndex>=0&&t.skinWeight>=0&&(j.enableVertexAttribArray(t.skinVertexA),j.enableVertexAttribArray(t.skinVertexB),j.enableVertexAttribArray(t.skinIndex),j.enableVertexAttribArray(t.skinWeight));if(b.attributes)for(h in b.attributes)t[h]!==void 0&&t[h]>=0&&j.enableVertexAttribArray(t[h]);if(b.morphTargets){b.numSupportedMorphTargets=0;t.morphTarget0>=0&&(j.enableVertexAttribArray(t.morphTarget0),b.numSupportedMorphTargets++);t.morphTarget1>=0&&(j.enableVertexAttribArray(t.morphTarget1),
b.numSupportedMorphTargets++);t.morphTarget2>=0&&(j.enableVertexAttribArray(t.morphTarget2),b.numSupportedMorphTargets++);t.morphTarget3>=0&&(j.enableVertexAttribArray(t.morphTarget3),b.numSupportedMorphTargets++);t.morphTarget4>=0&&(j.enableVertexAttribArray(t.morphTarget4),b.numSupportedMorphTargets++);t.morphTarget5>=0&&(j.enableVertexAttribArray(t.morphTarget5),b.numSupportedMorphTargets++);t.morphTarget6>=0&&(j.enableVertexAttribArray(t.morphTarget6),b.numSupportedMorphTargets++);t.morphTarget7>=
0&&(j.enableVertexAttribArray(t.morphTarget7),b.numSupportedMorphTargets++);f.__webglMorphTargetInfluences=new Float32Array(this.maxMorphTargets);b=0;for(h=this.maxMorphTargets;b<h;b++)f.__webglMorphTargetInfluences[b]=0}};this.render=function(b,c,o,z){var C,H,G,I,K,L,J,N,O=b.lights,P=b.fog;ea.data.vertices=0;ea.data.faces=0;ea.data.drawCalls=0;c.matrixAutoUpdate&&c.update(void 0,!0);b.update(void 0,!1,c);c.matrixWorldInverse.flattenToArray(la);c.projectionMatrix.flattenToArray(ka);Y.multiply(c.projectionMatrix,
c.matrixWorldInverse);n(Y);this.initWebGLObjects(b);F(o);(this.autoClear||z)&&this.clear();K=b.__webglObjects.length;for(z=0;z<K;z++)if(C=b.__webglObjects[z],J=C.object,J.visible)if(!(J instanceof THREE.Mesh)||p(J)){if(J.matrixWorld.flattenToArray(J._objectMatrixArray),y(J,c),v(C),C.render=!0,this.sortObjects)C.object.renderDepth?C.z=C.object.renderDepth:(ga.copy(J.position),Y.multiplyVector3(ga),C.z=ga.z)}else C.render=!1;else C.render=!1;this.sortObjects&&b.__webglObjects.sort(u);L=b.__webglObjectsImmediate.length;
M
Mr.doob 已提交
318 319 320
for(z=0;z<L;z++)C=b.__webglObjectsImmediate[z],J=C.object,J.visible&&(J.matrixAutoUpdate&&J.matrixWorld.flattenToArray(J._objectMatrixArray),y(J,c),t(C));if(b.overrideMaterial){h(b.overrideMaterial.depthTest);D(b.overrideMaterial.blending);for(z=0;z<K;z++)if(C=b.__webglObjects[z],C.render)J=C.object,N=C.buffer,k(J),f(c,O,P,b.overrideMaterial,N,J);for(z=0;z<L;z++)C=b.__webglObjectsImmediate[z],J=C.object,J.visible&&(k(J),H=e(c,O,P,b.overrideMaterial,J),J.render(function(e){g(e,H,b.overrideMaterial.shading)}))}else{D(THREE.NormalBlending);
for(z=0;z<K;z++)if(C=b.__webglObjects[z],C.render){J=C.object;N=C.buffer;G=C.opaque;k(J);for(C=0;C<G.count;C++)I=G.list[C],h(I.depthTest),m(I.polygonOffset,I.polygonOffsetFactor,I.polygonOffsetUnits),f(c,O,P,I,N,J)}for(z=0;z<L;z++)if(C=b.__webglObjectsImmediate[z],J=C.object,J.visible){G=C.opaque;k(J);for(C=0;C<G.count;C++)I=G.list[C],h(I.depthTest),m(I.polygonOffset,I.polygonOffsetFactor,I.polygonOffsetUnits),H=e(c,O,P,I,J),J.render(function(b){g(b,H,I.shading)})}for(z=0;z<K;z++)if(C=b.__webglObjects[z],
C.render){J=C.object;N=C.buffer;G=C.transparent;k(J);for(C=0;C<G.count;C++)I=G.list[C],D(I.blending),h(I.depthTest),m(I.polygonOffset,I.polygonOffsetFactor,I.polygonOffsetUnits),f(c,O,P,I,N,J)}for(z=0;z<L;z++)if(C=b.__webglObjectsImmediate[z],J=C.object,J.visible){G=C.transparent;k(J);for(C=0;C<G.count;C++)I=G.list[C],D(I.blending),h(I.depthTest),m(I.polygonOffset,I.polygonOffsetFactor,I.polygonOffsetUnits),H=e(c,O,P,I,J),J.render(function(b){g(b,H,I.shading)})}}b.__webglSprites.length&&B(b,c);Aa&&
321 322
b.__webglShadowVolumes.length&&b.lights.length&&w(b);b.__webglLensFlares.length&&A(b,c);o&&o.minFilter!==THREE.NearestFilter&&o.minFilter!==THREE.LinearFilter&&(j.bindTexture(j.TEXTURE_2D,o.__webglTexture),j.generateMipmap(j.TEXTURE_2D),j.bindTexture(j.TEXTURE_2D,null))};this.initWebGLObjects=function(b){if(!b.__webglObjects)b.__webglObjects=[],b.__webglObjectsImmediate=[],b.__webglShadowVolumes=[],b.__webglLensFlares=[],b.__webglSprites=[];for(;b.__objectsAdded.length;){var e=b.__objectsAdded[0],
c=b,f=void 0,h=void 0,g=void 0;if(e._modelViewMatrix==void 0)e._modelViewMatrix=new THREE.Matrix4,e._normalMatrixArray=new Float32Array(9),e._modelViewMatrixArray=new Float32Array(16),e._objectMatrixArray=new Float32Array(16),e.matrixWorld.flattenToArray(e._objectMatrixArray);if(e instanceof THREE.Mesh)for(f in h=e.geometry,h.geometryGroups==void 0&&C(h),h.geometryGroups){g=h.geometryGroups[f];if(!g.__webglVertexBuffer){var k=g;k.__webglVertexBuffer=j.createBuffer();k.__webglNormalBuffer=j.createBuffer();
M
Mr.doob 已提交
323
k.__webglTangentBuffer=j.createBuffer();k.__webglColorBuffer=j.createBuffer();k.__webglUVBuffer=j.createBuffer();k.__webglUV2Buffer=j.createBuffer();k.__webglSkinVertexABuffer=j.createBuffer();k.__webglSkinVertexBBuffer=j.createBuffer();k.__webglSkinIndicesBuffer=j.createBuffer();k.__webglSkinWeightsBuffer=j.createBuffer();k.__webglFaceBuffer=j.createBuffer();k.__webglLineBuffer=j.createBuffer();if(k.numMorphTargets){var m=void 0,o=void 0;k.__webglMorphTargetsBuffers=[];m=0;for(o=k.numMorphTargets;m<
324 325 326 327 328 329 330 331 332
o;m++)k.__webglMorphTargetsBuffers.push(j.createBuffer())}for(var k=g,m=e,t=void 0,p=void 0,n=void 0,u=n=void 0,v=void 0,w=void 0,y=w=o=0,A=n=p=void 0,B=A=p=t=void 0,n=void 0,u=m.geometry,v=u.faces,A=k.faces,t=0,p=A.length;t<p;t++)n=A[t],n=v[n],n instanceof THREE.Face3?(o+=3,w+=1,y+=3):n instanceof THREE.Face4&&(o+=4,w+=2,y+=4);for(var t=k,p=m,D=A=v=void 0,F=void 0,D=void 0,n=[],v=0,A=p.materials.length;v<A;v++)if(D=p.materials[v],D instanceof THREE.MeshFaceMaterial){D=0;for(l=t.materials.length;D<
l;D++)(F=t.materials[D])&&n.push(F)}else(F=D)&&n.push(F);t=n;k.__materials=t;a:{v=p=void 0;A=t.length;for(p=0;p<A;p++)if(v=t[p],v.map||v.lightMap||v instanceof THREE.MeshShaderMaterial){p=!0;break a}p=!1}a:{A=v=void 0;n=t.length;for(v=0;v<n;v++)if(A=t[v],!(A instanceof THREE.MeshBasicMaterial&&!A.envMap||A instanceof THREE.MeshDepthMaterial)){A=A&&A.shading!=void 0&&A.shading==THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading;break a}A=!1}a:{n=v=void 0;D=t.length;for(v=0;v<D;v++)if(n=t[v],
n.vertexColors){n=n.vertexColors;break a}n=!1}k.__vertexArray=new Float32Array(o*3);if(A)k.__normalArray=new Float32Array(o*3);if(u.hasTangents)k.__tangentArray=new Float32Array(o*4);if(n)k.__colorArray=new Float32Array(o*3);if(p){if(u.faceUvs.length>0||u.faceVertexUvs.length>0)k.__uvArray=new Float32Array(o*2);if(u.faceUvs.length>1||u.faceVertexUvs.length>1)k.__uv2Array=new Float32Array(o*2)}if(m.geometry.skinWeights.length&&m.geometry.skinIndices.length)k.__skinVertexAArray=new Float32Array(o*4),
k.__skinVertexBArray=new Float32Array(o*4),k.__skinIndexArray=new Float32Array(o*4),k.__skinWeightArray=new Float32Array(o*4);k.__faceArray=new Uint16Array(w*3+(m.geometry.edgeFaces?m.geometry.edgeFaces.length*6:0));k.__lineArray=new Uint16Array(y*2);if(k.numMorphTargets){k.__morphTargetsArrays=[];u=0;for(v=k.numMorphTargets;u<v;u++)k.__morphTargetsArrays.push(new Float32Array(o*3))}k.__needsSmoothNormals=A==THREE.SmoothShading;k.__uvType=p;k.__vertexColorType=n;k.__normalType=A;k.__webglFaceCount=
w*3+(m.geometry.edgeFaces?m.geometry.edgeFaces.length*6:0);k.__webglLineCount=y*2;u=0;for(v=t.length;u<v;u++)if(p=t[u],p.attributes)for(a in k.__webglCustomAttributes={},p.attributes){n=p.attributes[a];A={};for(B in n)A[B]=n[B];if(!A.__webglInitialized||A.createUniqueBuffers)A.__webglInitialized=!0,w=1,A.type==="v2"?w=2:A.type==="v3"?w=3:A.type==="v4"?w=4:A.type==="c"&&(w=3),A.size=w,A.array=new Float32Array(o*w),A.buffer=j.createBuffer(),A.buffer.belongsToAttribute=a,n.needsUpdate=!0,A.__original=
n;k.__webglCustomAttributes[a]=A}k.__inittedArrays=!0;h.__dirtyVertices=!0;h.__dirtyMorphTargets=!0;h.__dirtyElements=!0;h.__dirtyUvs=!0;h.__dirtyNormals=!0;h.__dirtyTangents=!0;h.__dirtyColors=!0}e instanceof THREE.ShadowVolume?H(c.__webglShadowVolumes,g,e):H(c.__webglObjects,g,e)}else if(e instanceof THREE.LensFlare)H(c.__webglLensFlares,void 0,e);else if(e instanceof THREE.Ribbon){h=e.geometry;if(!h.__webglVertexBuffer)f=h,f.__webglVertexBuffer=j.createBuffer(),f.__webglColorBuffer=j.createBuffer(),
f=h,g=f.vertices.length,f.__vertexArray=new Float32Array(g*3),f.__colorArray=new Float32Array(g*3),f.__webglVertexCount=g,h.__dirtyVertices=!0,h.__dirtyColors=!0;H(c.__webglObjects,h,e)}else if(e instanceof THREE.Line){h=e.geometry;if(!h.__webglVertexBuffer)f=h,f.__webglVertexBuffer=j.createBuffer(),f.__webglColorBuffer=j.createBuffer(),f=h,g=f.vertices.length,f.__vertexArray=new Float32Array(g*3),f.__colorArray=new Float32Array(g*3),f.__webglLineCount=g,h.__dirtyVertices=!0,h.__dirtyColors=!0;H(c.__webglObjects,
h,e)}else if(e instanceof THREE.ParticleSystem){h=e.geometry;if(!h.__webglVertexBuffer)f=h,f.__webglVertexBuffer=j.createBuffer(),f.__webglColorBuffer=j.createBuffer(),f=h,g=f.vertices.length,f.__vertexArray=new Float32Array(g*3),f.__colorArray=new Float32Array(g*3),f.__sortArray=[],f.__webglParticleCount=g,h.__dirtyVertices=!0,h.__dirtyColors=!0;H(c.__webglObjects,h,e)}else THREE.MarchingCubes!==void 0&&e instanceof THREE.MarchingCubes?c.__webglObjectsImmediate.push({object:e,opaque:{list:[],count:0},
transparent:{list:[],count:0}}):e instanceof THREE.Sprite&&c.__webglSprites.push(e);b.__objectsAdded.splice(0,1)}for(;b.__objectsRemoved.length;){c=b.__objectsRemoved[0];e=b;if(c instanceof THREE.ShadowVolume)z(e.__webglShadowVolumes,c);else if(c instanceof THREE.Mesh||c instanceof THREE.ParticleSystem||c instanceof THREE.Ribbon||c instanceof THREE.Line)z(e.__webglObjects,c);else if(c instanceof THREE.Sprite){e=e.__webglSprites;h=void 0;for(h=e.length-1;h>=0;h--)e[h]==c&&e.splice(h,1)}else c instanceof
M
Mr.doob 已提交
333 334
THREE.LensFlare?z(e.__webglLensFlares,c):c instanceof THREE.MarchingCubes&&z(e.__webglObjectsImmediate,c);b.__objectsRemoved.splice(0,1)}e=0;for(c=b.__webglObjects.length;e<c;e++)G(b.__webglObjects[e].object,b);e=0;for(c=b.__webglShadowVolumes.length;e<c;e++)G(b.__webglShadowVolumes[e].object,b);e=0;for(c=b.__webglLensFlares.length;e<c;e++)G(b.__webglLensFlares[e].object,b)};this.setFaceCulling=function(b,e){b?(!e||e=="ccw"?j.frontFace(j.CCW):j.frontFace(j.CW),b=="back"?j.cullFace(j.BACK):b=="front"?
j.cullFace(j.FRONT):j.cullFace(j.FRONT_AND_BACK),j.enable(j.CULL_FACE)):j.disable(j.CULL_FACE)};this.supportsVertexTextures=function(){return qa}};
M
Mr.doob 已提交
335
THREE.WebGLRenderTarget=function(b,c,e){this.width=b;this.height=c;e=e||{};this.wrapS=e.wrapS!==void 0?e.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=e.wrapT!==void 0?e.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=e.magFilter!==void 0?e.magFilter:THREE.LinearFilter;this.minFilter=e.minFilter!==void 0?e.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=e.format!==void 0?e.format:THREE.RGBAFormat;this.type=e.type!==void 0?e.type:
336
THREE.UnsignedByteType;this.depthBuffer=e.depthBuffer!==void 0?e.depthBuffer:!0;this.stencilBuffer=e.stencilBuffer!==void 0?e.stencilBuffer:!0};THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=!0};THREE.RenderableVertex.prototype.copy=function(b){this.positionWorld.copy(b.positionWorld);this.positionScreen.copy(b.positionScreen)};
337 338 339
THREE.RenderableFace3=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterials=this.meshMaterials=null;this.overdraw=!1;this.uvs=[[]];this.z=null};
THREE.RenderableFace4=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.v4=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterials=this.meshMaterials=null;this.overdraw=!1;this.uvs=[[]];this.z=null};
THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.materials=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.materials=null};
M
Mr.doob 已提交
340
THREE.ColorUtils={adjustHSV:function(b,c,e,f){var g=THREE.ColorUtils.__hsv;THREE.ColorUtils.rgbToHsv(b,g);g.h=THREE.ColorUtils.clamp(g.h+c,0,1);g.s=THREE.ColorUtils.clamp(g.s+e,0,1);g.v=THREE.ColorUtils.clamp(g.v+f,0,1);b.setHSV(g.h,g.s,g.v)},rgbToHsv:function(b,c){var e=b.r,f=b.g,g=b.b,k=Math.max(Math.max(e,f),g),h=Math.min(Math.min(e,f),g);if(h==k)h=e=0;else{var m=k-h,h=m/k,e=e==k?(f-g)/m:f==k?2+(g-e)/m:4+(e-f)/m;e/=6;e<0&&(e+=1);e>1&&(e-=1)}c===void 0&&(c={h:0,s:0,v:0});c.h=e;c.s=h;c.v=k;return c},
M
Mr.doob 已提交
341
clamp:function(b,c,e){return b<c?c:b>e?e:b}};THREE.ColorUtils.__hsv={h:0,s:0,v:0};
342 343
var GeometryUtils={merge:function(b,c){var e=c instanceof THREE.Mesh,f=b.vertices.length,g=e?c.geometry:c,k=b.vertices,h=g.vertices,m=b.faces,n=g.faces,p=b.faceVertexUvs[0],g=g.faceVertexUvs[0];e&&c.matrixAutoUpdate&&c.updateMatrix();for(var o=0,t=h.length;o<t;o++){var v=new THREE.Vertex(h[o].position.clone());e&&c.matrix.multiplyVector3(v.position);k.push(v)}o=0;for(t=n.length;o<t;o++){var h=n[o],u,w,B=h.vertexNormals,v=h.vertexColors;h instanceof THREE.Face3?u=new THREE.Face3(h.a+f,h.b+f,h.c+f):
h instanceof THREE.Face4&&(u=new THREE.Face4(h.a+f,h.b+f,h.c+f,h.d+f));u.normal.copy(h.normal);e=0;for(k=B.length;e<k;e++)w=B[e],u.vertexNormals.push(w.clone());u.color.copy(h.color);e=0;for(k=v.length;e<k;e++)w=v[e],u.vertexColors.push(w.clone());u.materials=h.materials.slice();u.centroid.copy(h.centroid);m.push(u)}o=0;for(t=g.length;o<t;o++){f=g[o];m=[];e=0;for(k=f.length;e<k;e++)m.push(new THREE.UV(f[e].u,f[e].v));p.push(m)}}};
M
Mr.doob 已提交
344
THREE.ImageUtils={loadTexture:function(b,c,e){var f=new Image,g=new THREE.Texture(f,c);f.onload=function(){g.needsUpdate=!0;e&&e(this)};f.crossOrigin="";f.src=b;return g},loadTextureCube:function(b,c,e){var f,g=[],k=new THREE.Texture(g,c),c=g.loadCount=0;for(f=b.length;c<f;++c)g[c]=new Image,g[c].onload=function(){g.loadCount+=1;if(g.loadCount==6)k.needsUpdate=!0;e&&e(this)},g[c].crossOrigin="",g[c].src=b[c];return k}};
M
Mr.doob 已提交
345 346
THREE.SceneUtils={showHierarchy:function(b,c){THREE.SceneUtils.traverseHierarchy(b,function(b){b.visible=c})},traverseHierarchy:function(b,c){var e,f,g=b.children.length;for(f=0;f<g;f++)e=b.children[f],c(e),THREE.SceneUtils.traverseHierarchy(e,c)}};
if(THREE.WebGLRenderer)THREE.ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",vertexShader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"},
A
alteredq 已提交
347 348
normal:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},enableSpecular:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},tNormal:{type:"t",value:2,texture:null},tSpecular:{type:"t",value:3,texture:null},tAO:{type:"t",value:4,texture:null},uNormalScale:{type:"f",value:1},tDisplacement:{type:"t",value:5,texture:null},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},uDiffuseColor:{type:"c",
value:new THREE.Color(15658734)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(328965)},uShininess:{type:"f",value:30},uOpacity:{type:"f",value:1}}]),fragmentShader:["uniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform float uOpacity;\nuniform bool enableDiffuse;\nuniform bool enableSpecular;\nuniform bool enableAO;\nuniform sampler2D tDiffuse;\nuniform sampler2D tNormal;\nuniform sampler2D tSpecular;\nuniform sampler2D tAO;\nuniform float uNormalScale;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;",
349
THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( 1.0 );\nvec4 mColor = vec4( uDiffuseColor, uOpacity );\nvec4 mSpecular = vec4( uSpecularColor, uOpacity );\nvec3 specularTex = vec3( 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse )\ngl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );\nif( enableAO )\ngl_FragColor = gl_FragColor * texture2D( tAO, vUv );\nif( enableSpecular )\nspecularTex = texture2D( tSpecular, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointTotal  = vec4( 0.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec3 pointVector = normalize( vPointLight[ i ].xyz );\nvec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );\nfloat pointDistance = vPointLight[ i ].w;\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );\npointTotal  += pointDistance * vec4( pointLightColor[ i ], 1.0 ) * ( mColor * pointDiffuseWeight + mSpecular * pointSpecularWeight * pointDiffuseWeight );\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirTotal  = 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 + viewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );\ndirTotal  += vec4( directionalLightColor[ i ], 1.0 ) * ( mColor * dirDiffuseWeight + mSpecular * dirSpecularWeight * dirDiffuseWeight );\n}\n#endif\nvec4 totalLight = vec4( ambientLightColor * uAmbientColor, uOpacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirTotal;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointTotal;\n#endif\ngl_FragColor = gl_FragColor * totalLight;",
A
alteredq 已提交
350
THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:"attribute vec4 tangent;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"},
351 352 353 354
cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertexShader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"},convolution:{uniforms:{tDiffuse:{type:"t",
value:0,texture:null},uImageIncrement:{type:"v2",value:new THREE.Vector2(0.001953125,0)},cKernel:{type:"fv1",value:[]}},vertexShader:"varying vec2 vUv;\nuniform vec2 uImageIncrement;\nvoid main(void) {\nvUv = uv - ((KERNEL_SIZE - 1.0) / 2.0) * uImageIncrement;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"varying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform vec2 uImageIncrement;\nuniform float cKernel[KERNEL_SIZE];\nvoid main(void) {\nvec2 imageCoord = vUv;\nvec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 );\nfor( int i=0; i<KERNEL_SIZE; ++i ) {\nsum += texture2D( tDiffuse, imageCoord ) * cKernel[i];\nimageCoord += uImageIncrement;\n}\ngl_FragColor = sum;\n}"},
film:{uniforms:{tDiffuse:{type:"t",value:0,texture:null},time:{type:"f",value:0},nIntensity:{type:"f",value:0.5},sIntensity:{type:"f",value:0.05},sCount:{type:"f",value:4096},grayscale:{type:"i",value:1}},vertexShader:"varying vec2 vUv;\nvoid main() {\nvUv = vec2( uv.x, 1.0 - uv.y );\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"varying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform float time;\nuniform bool grayscale;\nuniform float nIntensity;\nuniform float sIntensity;\nuniform float sCount;\nvoid main() {\nvec4 cTextureScreen = texture2D( tDiffuse, vUv );\nfloat x = vUv.x * vUv.y * time *  1000.0;\nx = mod( x, 13.0 ) * mod( x, 123.0 );\nfloat dx = mod( x, 0.01 );\nvec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx * 100.0, 0.0, 1.0 );\nvec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );\ncResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;\ncResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );\nif( grayscale ) {\ncResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );\n}\ngl_FragColor =  vec4( cResult, cTextureScreen.a );\n}"},
screen:{uniforms:{tDiffuse:{type:"t",value:0,texture:null},opacity:{type:"f",value:1}},vertexShader:"varying vec2 vUv;\nvoid main() {\nvUv = vec2( uv.x, 1.0 - uv.y );\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"varying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform float opacity;\nvoid main() {\nvec4 texel = texture2D( tDiffuse, vUv );\ngl_FragColor = opacity * texel;\n}"},basic:{uniforms:{},vertexShader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",
M
Mr.doob 已提交
355
fragmentShader:"void main() {\ngl_FragColor = vec4( 1.0, 0.0, 0.0, 0.5 );\n}"}},buildKernel:function(b){var c,e,f,g,k=2*Math.ceil(b*3)+1;k>25&&(k=25);g=(k-1)*0.5;e=Array(k);for(c=f=0;c<k;++c)e[c]=Math.exp(-((c-g)*(c-g))/(2*b*b)),f+=e[c];for(c=0;c<k;++c)e[c]/=f;return e}};
M
Mr.doob 已提交
356
THREE.AnimationHandler=function(){var b=[],c={},e={update:function(e){for(var c=0;c<b.length;c++)b[c].update(e)},addToUpdate:function(e){b.indexOf(e)===-1&&b.push(e)},removeFromUpdate:function(e){e=b.indexOf(e);e!==-1&&b.splice(e,1)},add:function(b){c[b.name]!==void 0&&console.log("THREE.AnimationHandler.add: Warning! "+b.name+" already exists in library. Overwriting.");c[b.name]=b;if(b.initialized!==!0){for(var e=0;e<b.hierarchy.length;e++){for(var f=0;f<b.hierarchy[e].keys.length;f++){if(b.hierarchy[e].keys[f].time<
357 358
0)b.hierarchy[e].keys[f].time=0;if(b.hierarchy[e].keys[f].rot!==void 0&&!(b.hierarchy[e].keys[f].rot instanceof THREE.Quaternion)){var m=b.hierarchy[e].keys[f].rot;b.hierarchy[e].keys[f].rot=new THREE.Quaternion(m[0],m[1],m[2],m[3])}}if(b.hierarchy[e].keys[0].morphTargets!==void 0){m={};for(f=0;f<b.hierarchy[e].keys.length;f++)for(var n=0;n<b.hierarchy[e].keys[f].morphTargets.length;n++){var p=b.hierarchy[e].keys[f].morphTargets[n];m[p]=-1}b.hierarchy[e].usedMorphTargets=m;for(f=0;f<b.hierarchy[e].keys.length;f++){var o=
{};for(p in m){for(n=0;n<b.hierarchy[e].keys[f].morphTargets.length;n++)if(b.hierarchy[e].keys[f].morphTargets[n]===p){o[p]=b.hierarchy[e].keys[f].morphTargetsInfluences[n];break}n===b.hierarchy[e].keys[f].morphTargets.length&&(o[p]=0)}b.hierarchy[e].keys[f].morphTargetsInfluences=o}}for(f=1;f<b.hierarchy[e].keys.length;f++)b.hierarchy[e].keys[f].time===b.hierarchy[e].keys[f-1].time&&(b.hierarchy[e].keys.splice(f,1),f--);for(f=1;f<b.hierarchy[e].keys.length;f++)b.hierarchy[e].keys[f].index=f}f=parseInt(b.length*
M
Mr.doob 已提交
359 360 361
b.fps,10);b.JIT={};b.JIT.hierarchy=[];for(e=0;e<b.hierarchy.length;e++)b.JIT.hierarchy.push(Array(f));b.initialized=!0}},get:function(b){if(typeof b==="string")return c[b]?c[b]:(console.log("THREE.AnimationHandler.get: Couldn't find animation "+b),null)},parse:function(b){var e=[];if(b instanceof THREE.SkinnedMesh)for(var c=0;c<b.bones.length;c++)e.push(b.bones[c]);else f(b,e);return e}},f=function(b,e){e.push(b);for(var c=0;c<b.children.length;c++)f(b.children[c],e)};e.LINEAR=0;e.CATMULLROM=1;e.CATMULLROM_FORWARD=
2;return e}();THREE.Animation=function(b,c,e,f){this.root=b;this.data=THREE.AnimationHandler.get(c);this.hierarchy=THREE.AnimationHandler.parse(b);this.currentTime=0;this.timeScale=1;this.isPlaying=!1;this.loop=this.isPaused=!0;this.interpolationType=e!==void 0?e:THREE.AnimationHandler.LINEAR;this.JITCompile=f!==void 0?f:!0;this.points=[];this.target=new THREE.Vector3};
THREE.Animation.prototype.play=function(b,c){if(!this.isPlaying){this.isPlaying=!0;this.loop=b!==void 0?b:!0;this.currentTime=c!==void 0?c:0;var e,f=this.hierarchy.length,g;for(e=0;e<f;e++){g=this.hierarchy[e];if(this.interpolationType!==THREE.AnimationHandler.CATMULLROM_FORWARD)g.useQuaternion=!0;g.matrixAutoUpdate=!0;if(g.animationCache===void 0)g.animationCache={},g.animationCache.prevKey={pos:0,rot:0,scl:0},g.animationCache.nextKey={pos:0,rot:0,scl:0},g.animationCache.originalMatrix=g instanceof
M
Mr.doob 已提交
362
THREE.Bone?g.skinMatrix:g.matrix;var k=g.animationCache.prevKey;g=g.animationCache.nextKey;k.pos=this.data.hierarchy[e].keys[0];k.rot=this.data.hierarchy[e].keys[0];k.scl=this.data.hierarchy[e].keys[0];g.pos=this.getNextKeyWith("pos",e,1);g.rot=this.getNextKeyWith("rot",e,1);g.scl=this.getNextKeyWith("scl",e,1)}this.update(0)}this.isPaused=!1;THREE.AnimationHandler.addToUpdate(this)};
363 364
THREE.Animation.prototype.pause=function(){this.isPaused?THREE.AnimationHandler.addToUpdate(this):THREE.AnimationHandler.removeFromUpdate(this);this.isPaused=!this.isPaused};
THREE.Animation.prototype.stop=function(){this.isPaused=this.isPlaying=!1;THREE.AnimationHandler.removeFromUpdate(this);for(var b=0;b<this.hierarchy.length;b++)if(this.hierarchy[b].animationCache!==void 0)this.hierarchy[b]instanceof THREE.Bone?this.hierarchy[b].skinMatrix=this.hierarchy[b].animationCache.originalMatrix:this.hierarchy[b].matrix=this.hierarchy[b].animationCache.originalMatrix,delete this.hierarchy[b].animationCache};
365 366
THREE.Animation.prototype.update=function(b){if(this.isPlaying){var c=["pos","rot","scl"],e,f,g,k,h,m,n,p,o=this.data.JIT.hierarchy,t,v;this.currentTime+=b*this.timeScale;v=this.currentTime;t=this.currentTime%=this.data.length;p=parseInt(Math.min(t*this.data.fps,this.data.length*this.data.fps),10);for(var u=0,w=this.hierarchy.length;u<w;u++)if(b=this.hierarchy[u],n=b.animationCache,this.JITCompile&&o[u][p]!==void 0)b instanceof THREE.Bone?(b.skinMatrix=o[u][p],b.matrixAutoUpdate=!1,b.matrixWorldNeedsUpdate=
!1):(b.matrix=o[u][p],b.matrixAutoUpdate=!1,b.matrixWorldNeedsUpdate=!0);else{if(this.JITCompile)b instanceof THREE.Bone?b.skinMatrix=b.animationCache.originalMatrix:b.matrix=b.animationCache.originalMatrix;for(var B=0;B<3;B++){e=c[B];h=n.prevKey[e];m=n.nextKey[e];if(m.time<=v){if(t<v)if(this.loop){h=this.data.hierarchy[u].keys[0];for(m=this.getNextKeyWith(e,u,1);m.time<t;)h=m,m=this.getNextKeyWith(e,u,m.index+1)}else{this.stop();return}else{do h=m,m=this.getNextKeyWith(e,u,m.index+1);while(m.time<
M
Mr.doob 已提交
367
t)}n.prevKey[e]=h;n.nextKey[e]=m}b.matrixAutoUpdate=!0;b.matrixWorldNeedsUpdate=!0;f=(t-h.time)/(m.time-h.time);g=h[e];k=m[e];if(f<0||f>1)console.log("THREE.Animation.update: Warning! Scale out of bounds:"+f+" on bone "+u),f=f<0?0:1;if(e==="pos")if(e=b.position,this.interpolationType===THREE.AnimationHandler.LINEAR)e.x=g[0]+(k[0]-g[0])*f,e.y=g[1]+(k[1]-g[1])*f,e.z=g[2]+(k[2]-g[2])*f;else{if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD)if(this.points[0]=
M
Mr.doob 已提交
368
this.getPrevKeyWith("pos",u,h.index-1).pos,this.points[1]=g,this.points[2]=k,this.points[3]=this.getNextKeyWith("pos",u,m.index+1).pos,f=f*0.33+0.33,g=this.interpolateCatmullRom(this.points,f),e.x=g[0],e.y=g[1],e.z=g[2],this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD)f=this.interpolateCatmullRom(this.points,f*1.01),this.target.set(f[0],f[1],f[2]),this.target.subSelf(e),this.target.y=0,this.target.normalize(),f=Math.atan2(this.target.x,this.target.z),b.rotation.set(0,f,0)}else if(e===
369 370
"rot")THREE.Quaternion.slerp(g,k,b.quaternion,f);else if(e==="scl")e=b.scale,e.x=g[0]+(k[0]-g[0])*f,e.y=g[1]+(k[1]-g[1])*f,e.z=g[2]+(k[2]-g[2])*f}}if(this.JITCompile&&o[0][p]===void 0){this.hierarchy[0].update(void 0,!0);for(u=0;u<this.hierarchy.length;u++)o[u][p]=this.hierarchy[u]instanceof THREE.Bone?this.hierarchy[u].skinMatrix.clone():this.hierarchy[u].matrix.clone()}}};
THREE.Animation.prototype.interpolateCatmullRom=function(b,c){var e=[],f=[],g,k,h,m,n,p;g=(b.length-1)*c;k=Math.floor(g);g-=k;e[0]=k==0?k:k-1;e[1]=k;e[2]=k>b.length-2?k:k+1;e[3]=k>b.length-3?k:k+2;k=b[e[0]];m=b[e[1]];n=b[e[2]];p=b[e[3]];e=g*g;h=g*e;f[0]=this.interpolate(k[0],m[0],n[0],p[0],g,e,h);f[1]=this.interpolate(k[1],m[1],n[1],p[1],g,e,h);f[2]=this.interpolate(k[2],m[2],n[2],p[2],g,e,h);return f};
M
Mr.doob 已提交
371
THREE.Animation.prototype.interpolate=function(b,c,e,f,g,k,h){b=(e-b)*0.5;f=(f-c)*0.5;return(2*(c-e)+b+f)*h+(-3*(c-e)-2*b-f)*k+b*g+c};THREE.Animation.prototype.getNextKeyWith=function(b,c,e){var f=this.data.hierarchy[c].keys;for(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?e=e<f.length-1?e:f.length-1:e%=f.length;e<f.length;e++)if(f[e][b]!==void 0)return f[e];return this.data.hierarchy[c].keys[0]};
M
Mr.doob 已提交
372
THREE.Animation.prototype.getPrevKeyWith=function(b,c,e){for(var f=this.data.hierarchy[c].keys,e=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?e>0?e:0:e>=0?e:e+f.length;e>=0;e--)if(f[e][b]!==void 0)return f[e];return this.data.hierarchy[c].keys[f.length-1]};
A
alteredq 已提交
373
THREE.FirstPersonCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.movementSpeed=1;this.lookSpeed=0.0050;this.noFly=!1;this.lookVertical=!0;this.autoForward=!1;this.activeLook=!0;this.heightSpeed=!1;this.heightCoef=1;this.heightMin=0;this.constrainVertical=!1;this.verticalMin=0;this.verticalMax=3.14;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(b){if(b.movementSpeed!==void 0)this.movementSpeed=
374 375 376 377 378
b.movementSpeed;if(b.lookSpeed!==void 0)this.lookSpeed=b.lookSpeed;if(b.noFly!==void 0)this.noFly=b.noFly;if(b.lookVertical!==void 0)this.lookVertical=b.lookVertical;if(b.autoForward!==void 0)this.autoForward=b.autoForward;if(b.activeLook!==void 0)this.activeLook=b.activeLook;if(b.heightSpeed!==void 0)this.heightSpeed=b.heightSpeed;if(b.heightCoef!==void 0)this.heightCoef=b.heightCoef;if(b.heightMin!==void 0)this.heightMin=b.heightMin;if(b.heightMax!==void 0)this.heightMax=b.heightMax;if(b.constrainVertical!==
void 0)this.constrainVertical=b.constrainVertical;if(b.verticalMin!==void 0)this.verticalMin=b.verticalMin;if(b.verticalMax!==void 0)this.verticalMax=b.verticalMax;if(b.domElement!==void 0)this.domElement=b.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=this.autoSpeedFactor=0;this.mouseDragOn=this.freeze=this.moveRight=this.moveLeft=this.moveBackward=this.moveForward=!1;this.windowHalfX=window.innerWidth/2;this.windowHalfY=window.innerHeight/2;this.onMouseDown=function(b){b.preventDefault();
b.stopPropagation();if(this.activeLook)switch(b.button){case 0:this.moveForward=!0;break;case 2:this.moveBackward=!0}this.mouseDragOn=!0};this.onMouseUp=function(b){b.preventDefault();b.stopPropagation();if(this.activeLook)switch(b.button){case 0:this.moveForward=!1;break;case 2:this.moveBackward=!1}this.mouseDragOn=!1};this.onMouseMove=function(b){this.mouseX=b.clientX-this.windowHalfX;this.mouseY=b.clientY-this.windowHalfY};this.onKeyDown=function(b){switch(b.keyCode){case 38:case 87:this.moveForward=
!0;break;case 37:case 65:this.moveLeft=!0;break;case 40:case 83:this.moveBackward=!0;break;case 39:case 68:this.moveRight=!0;break;case 81:this.freeze=!this.freeze}};this.onKeyUp=function(b){switch(b.keyCode){case 38:case 87:this.moveForward=!1;break;case 37:case 65:this.moveLeft=!1;break;case 40:case 83:this.moveBackward=!1;break;case 39:case 68:this.moveRight=!1}};this.update=function(){var b=(new Date).getTime();this.tdiff=(b-this.lastUpdate)/1E3;this.lastUpdate=b;if(!this.freeze){this.autoSpeedFactor=
this.heightSpeed?this.tdiff*((this.position.y<this.heightMin?this.heightMin:this.position.y>this.heightMax?this.heightMax:this.position.y)-this.heightMin)*this.heightCoef:0;var c=this.tdiff*this.movementSpeed;(this.moveForward||this.autoForward&&!this.moveBackward)&&this.translateZ(-(c+this.autoSpeedFactor));this.moveBackward&&this.translateZ(c);this.moveLeft&&this.translateX(-c);this.moveRight&&this.translateX(c);c=this.tdiff*this.lookSpeed;this.activeLook||(c=0);this.lon+=this.mouseX*c;this.lookVertical&&
M
Mr.doob 已提交
379 380 381 382
(this.lat-=this.mouseY*c);this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI/180;this.theta=this.lon*Math.PI/180;var b=this.target.position,g=this.position;b.x=g.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=g.y+100*Math.cos(this.phi);b.z=g.z+100*Math.sin(this.phi)*Math.sin(this.theta)}this.lon+=this.mouseX*c;this.lookVertical&&(this.lat-=this.mouseY*c);this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI/180;this.theta=this.lon*Math.PI/180;if(this.constrainVertical)this.phi=
(this.phi-0)*(this.verticalMax-this.verticalMin)/3.14+this.verticalMin;b=this.target.position;g=this.position;b.x=g.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=g.y+100*Math.cos(this.phi);b.z=g.z+100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this)};this.domElement.addEventListener("contextmenu",function(b){b.preventDefault()},!1);this.domElement.addEventListener("mousemove",c(this,this.onMouseMove),!1);this.domElement.addEventListener("mousedown",c(this,this.onMouseDown),
!1);this.domElement.addEventListener("mouseup",c(this,this.onMouseUp),!1);this.domElement.addEventListener("keydown",c(this,this.onKeyDown),!1);this.domElement.addEventListener("keyup",c(this,this.onKeyUp),!1)};THREE.FirstPersonCamera.prototype=new THREE.Camera;THREE.FirstPersonCamera.prototype.constructor=THREE.FirstPersonCamera;THREE.FirstPersonCamera.prototype.supr=THREE.Camera.prototype;
THREE.FirstPersonCamera.prototype.translate=function(b,c){this.matrix.rotateAxis(c);if(this.noFly)c.y=0;this.position.addSelf(c.multiplyScalar(b));this.target.position.addSelf(c.multiplyScalar(b))};
383
THREE.PathCamera=function(b){function c(b,e,c,f){var h={name:c,fps:0.6,length:f,hierarchy:[]},g,k=e.getControlPointsArray(),m=e.getLength(),n=k.length,G=0;g=n-1;e={parent:-1,keys:[]};e.keys[0]={time:0,pos:k[0],rot:[0,0,0,1],scl:[1,1,1]};e.keys[g]={time:f,pos:k[g],rot:[0,0,0,1],scl:[1,1,1]};for(g=1;g<n-1;g++)G=f*m.chunks[g]/m.total,e.keys[g]={time:G,pos:k[g]};h.hierarchy[0]=e;THREE.AnimationHandler.add(h);return new THREE.Animation(b,c,THREE.AnimationHandler.CATMULLROM_FORWARD,!1)}function e(b,e){var c,
384
f,h=new THREE.Geometry;for(c=0;c<b.points.length*e;c++)f=c/(b.points.length*e),f=b.getPoint(f),h.vertices[c]=new THREE.Vertex(new THREE.Vector3(f.x,f.y,f.z));return h}function f(b,c){var f=e(c,10),h=e(c,10),g=new THREE.LineBasicMaterial({color:16711680,linewidth:3});lineObj=new THREE.Line(f,g);particleObj=new THREE.ParticleSystem(h,new THREE.ParticleBasicMaterial({color:16755200,size:3}));lineObj.scale.set(1,1,1);b.addChild(lineObj);particleObj.scale.set(1,1,1);b.addChild(particleObj);h=new THREE.SphereGeometry(1,
A
alteredq 已提交
385
16,8);g=new THREE.MeshBasicMaterial({color:65280});for(i=0;i<c.points.length;i++)f=new THREE.Mesh(h,g),f.position.copy(c.points[i]),f.updateMatrix(),b.addChild(f)}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.id="PathCamera"+THREE.PathCameraIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=!0;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;this.animationParent=new THREE.Object3D;this.lookSpeed=0.0050;this.lookHorizontal=
386 387
this.lookVertical=!0;this.verticalAngleMap={srcRange:[0,6.28],dstRange:[0,6.28]};this.horizontalAngleMap={srcRange:[0,6.28],dstRange:[0,6.28]};this.domElement=document;if(b){if(b.duration!==void 0)this.duration=b.duration*1E3;if(b.waypoints!==void 0)this.waypoints=b.waypoints;if(b.useConstantSpeed!==void 0)this.useConstantSpeed=b.useConstantSpeed;if(b.resamplingCoef!==void 0)this.resamplingCoef=b.resamplingCoef;if(b.createDebugPath!==void 0)this.createDebugPath=b.createDebugPath;if(b.createDebugDummy!==
void 0)this.createDebugDummy=b.createDebugDummy;if(b.lookSpeed!==void 0)this.lookSpeed=b.lookSpeed;if(b.lookVertical!==void 0)this.lookVertical=b.lookVertical;if(b.lookHorizontal!==void 0)this.lookHorizontal=b.lookHorizontal;if(b.verticalAngleMap!==void 0)this.verticalAngleMap=b.verticalAngleMap;if(b.horizontalAngleMap!==void 0)this.horizontalAngleMap=b.horizontalAngleMap;if(b.domElement!==void 0)this.domElement=b.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=0;this.windowHalfX=
M
Mr.doob 已提交
388 389
window.innerWidth/2;this.windowHalfY=window.innerHeight/2;var g=Math.PI*2,k=Math.PI/180;this.update=function(b,e,c){var f,h;this.lookHorizontal&&(this.lon+=this.mouseX*this.lookSpeed);this.lookVertical&&(this.lat-=this.mouseY*this.lookSpeed);this.lon=Math.max(0,Math.min(360,this.lon));this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*k;this.theta=this.lon*k;f=this.phi%g;this.phi=f>=0?f:f+g;f=this.verticalAngleMap.srcRange;h=this.verticalAngleMap.dstRange;var m=h[1]-h[0];this.phi=
TWEEN.Easing.Quadratic.EaseInOut(((this.phi-f[0])*(h[1]-h[0])/(f[1]-f[0])+h[0]-h[0])/m)*m+h[0];f=this.horizontalAngleMap.srcRange;h=this.horizontalAngleMap.dstRange;m=h[1]-h[0];this.theta=TWEEN.Easing.Quadratic.EaseInOut(((this.theta-f[0])*(h[1]-h[0])/(f[1]-f[0])+h[0]-h[0])/m)*m+h[0];f=this.target.position;f.x=100*Math.sin(this.phi)*Math.cos(this.theta);f.y=100*Math.cos(this.phi);f.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this,b,e,c)};this.onMouseMove=function(b){this.mouseX=
M
Mr.doob 已提交
390
b.clientX-this.windowHalfX;this.mouseY=b.clientY-this.windowHalfY};this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){var b=new THREE.MeshLambertMaterial({color:30719}),h=new THREE.MeshLambertMaterial({color:65280}),m=new THREE.CubeGeometry(10,10,20),n=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(m,b);b=new THREE.Mesh(n,h);b.position.set(0,10,0);this.animation=
M
Mr.doob 已提交
391
c(this.animationParent,this.spline,this.id,this.duration);this.animationParent.addChild(this);this.animationParent.addChild(this.target);this.animationParent.addChild(b)}else this.animation=c(this.animationParent,this.spline,this.id,this.duration),this.animationParent.addChild(this.target),this.animationParent.addChild(this);this.createDebugPath&&f(this.debugPath,this.spline);this.domElement.addEventListener("mousemove",function(b,e){return function(){e.apply(b,arguments)}}(this,this.onMouseMove),
392
!1)};THREE.PathCamera.prototype=new THREE.Camera;THREE.PathCamera.prototype.constructor=THREE.PathCamera;THREE.PathCamera.prototype.supr=THREE.Camera.prototype;THREE.PathCameraIdCounter=0;
A
alteredq 已提交
393
THREE.FlyCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.0050;this.autoForward=this.dragToLook=!1;this.domElement=document;if(b){if(b.movementSpeed!==void 0)this.movementSpeed=b.movementSpeed;if(b.rollSpeed!==void 0)this.rollSpeed=b.rollSpeed;if(b.dragToLook!==void 0)this.dragToLook=b.dragToLook;if(b.autoForward!==void 0)this.autoForward=
394 395 396
b.autoForward;if(b.domElement!==void 0)this.domElement=b.domElement}this.useTarget=!1;this.useQuaternion=!0;this.mouseStatus=0;this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0};this.moveVector=new THREE.Vector3(0,0,0);this.rotationVector=new THREE.Vector3(0,0,0);this.lastUpdate=-1;this.tdiff=0;this.handleEvent=function(b){if(typeof this[b.type]=="function")this[b.type](b)};this.keydown=function(b){if(!b.altKey){switch(b.keyCode){case 16:this.movementSpeedMultiplier=
0.1;break;case 87:this.moveState.forward=1;break;case 83:this.moveState.back=1;break;case 65:this.moveState.left=1;break;case 68:this.moveState.right=1;break;case 82:this.moveState.up=1;break;case 70:this.moveState.down=1;break;case 38:this.moveState.pitchUp=1;break;case 40:this.moveState.pitchDown=1;break;case 37:this.moveState.yawLeft=1;break;case 39:this.moveState.yawRight=1;break;case 81:this.moveState.rollLeft=1;break;case 69:this.moveState.rollRight=1}this.updateMovementVector();this.updateRotationVector()}};
this.keyup=function(b){switch(b.keyCode){case 16:this.movementSpeedMultiplier=1;break;case 87:this.moveState.forward=0;break;case 83:this.moveState.back=0;break;case 65:this.moveState.left=0;break;case 68:this.moveState.right=0;break;case 82:this.moveState.up=0;break;case 70:this.moveState.down=0;break;case 38:this.moveState.pitchUp=0;break;case 40:this.moveState.pitchDown=0;break;case 37:this.moveState.yawLeft=0;break;case 39:this.moveState.yawRight=0;break;case 81:this.moveState.rollLeft=0;break;
M
Mr.doob 已提交
397 398
case 69:this.moveState.rollRight=0}this.updateMovementVector();this.updateRotationVector()};this.mousedown=function(b){b.preventDefault();b.stopPropagation();if(this.dragToLook)this.mouseStatus++;else switch(b.button){case 0:this.moveForward=!0;break;case 2:this.moveBackward=!0}};this.mousemove=function(b){if(!this.dragToLook||this.mouseStatus>0){var c=this.getContainerDimensions(),g=c.size[0]/2,k=c.size[1]/2;this.moveState.yawLeft=-(b.clientX-c.offset[0]-g)/g;this.moveState.pitchDown=(b.clientY-
c.offset[1]-k)/k;this.updateRotationVector()}};this.mouseup=function(b){b.preventDefault();b.stopPropagation();if(this.dragToLook)this.mouseStatus--,this.moveState.yawLeft=this.moveState.pitchDown=0;else switch(b.button){case 0:this.moveForward=!1;break;case 2:this.moveBackward=!1}this.updateRotationVector()};this.update=function(){var b=(new Date).getTime();if(this.lastUpdate==-1)this.lastUpdate=b;this.tdiff=(b-this.lastUpdate)/1E3;this.lastUpdate=b;var b=this.tdiff*this.movementSpeed,c=this.tdiff*
399 400 401 402
this.rollSpeed;this.translateX(this.moveVector.x*b);this.translateY(this.moveVector.y*b);this.translateZ(this.moveVector.z*b);this.tmpQuaternion.set(this.rotationVector.x*c,this.rotationVector.y*c,this.rotationVector.z*c,1).normalize();this.quaternion.multiplySelf(this.tmpQuaternion);this.matrix.setPosition(this.position);this.matrix.setRotationFromQuaternion(this.quaternion);this.matrixWorldNeedsUpdate=!0;this.supr.update.call(this)};this.updateMovementVector=function(){var b=this.moveState.forward||
this.autoForward&&!this.moveState.back?1:0;this.moveVector.x=-this.moveState.left+this.moveState.right;this.moveVector.y=-this.moveState.down+this.moveState.up;this.moveVector.z=-b+this.moveState.back};this.updateRotationVector=function(){this.rotationVector.x=-this.moveState.pitchDown+this.moveState.pitchUp;this.rotationVector.y=-this.moveState.yawRight+this.moveState.yawLeft;this.rotationVector.z=-this.moveState.rollRight+this.moveState.rollLeft};this.getContainerDimensions=function(){return this.domElement!=
document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}};this.domElement.addEventListener("mousemove",c(this,this.mousemove),!1);this.domElement.addEventListener("mousedown",c(this,this.mousedown),!1);this.domElement.addEventListener("mouseup",c(this,this.mouseup),!1);window.addEventListener("keydown",c(this,this.keydown),!1);window.addEventListener("keyup",c(this,
this.keyup),!1);this.updateMovementVector();this.updateRotationVector()};THREE.FlyCamera.prototype=new THREE.Camera;THREE.FlyCamera.prototype.constructor=THREE.FlyCamera;THREE.FlyCamera.prototype.supr=THREE.Camera.prototype;
403 404
THREE.RollCamera=function(b,c,e,f){THREE.Camera.call(this,b,c,e,f);this.mouseLook=!0;this.autoForward=!1;this.rollSpeed=this.movementSpeed=this.lookSpeed=1;this.constrainVertical=[-0.9,0.9];this.domElement=document;this.matrixAutoUpdate=this.useTarget=!1;this.forward=new THREE.Vector3(0,0,1);this.roll=0;this.lastUpdate=-1;this.delta=0;var g=new THREE.Vector3,k=new THREE.Vector3,h=new THREE.Vector3,m=new THREE.Matrix4,n=!1,p=1,o=0,t=0,v=0,u=0,w=0,B=window.innerWidth/2,A=window.innerHeight/2;this.update=
function(){var b=(new Date).getTime();if(this.lastUpdate==-1)this.lastUpdate=b;this.delta=(b-this.lastUpdate)/1E3;this.lastUpdate=b;this.mouseLook&&(b=this.delta*this.lookSpeed,this.rotateHorizontally(b*u),this.rotateVertically(b*w));b=this.delta*this.movementSpeed;this.translateZ(b*(o>0||this.autoForward&&!(o<0)?1:o));this.translateX(b*t);this.translateY(b*v);n&&(this.roll+=this.rollSpeed*this.delta*p);if(this.forward.y>this.constrainVertical[1])this.forward.y=this.constrainVertical[1],this.forward.normalize();
M
Mr.doob 已提交
405
else if(this.forward.y<this.constrainVertical[0])this.forward.y=this.constrainVertical[0],this.forward.normalize();h.copy(this.forward);k.set(0,1,0);g.cross(k,h).normalize();k.cross(h,g).normalize();this.matrix.n11=g.x;this.matrix.n12=k.x;this.matrix.n13=h.x;this.matrix.n21=g.y;this.matrix.n22=k.y;this.matrix.n23=h.y;this.matrix.n31=g.z;this.matrix.n32=k.z;this.matrix.n33=h.z;m.identity();m.n11=Math.cos(this.roll);m.n12=-Math.sin(this.roll);m.n21=Math.sin(this.roll);m.n22=Math.cos(this.roll);this.matrix.multiplySelf(m);
406
this.matrixWorldNeedsUpdate=!0;this.matrix.n14=this.position.x;this.matrix.n24=this.position.y;this.matrix.n34=this.position.z;this.supr.update.call(this)};this.translateX=function(b){this.position.x+=this.matrix.n11*b;this.position.y+=this.matrix.n21*b;this.position.z+=this.matrix.n31*b};this.translateY=function(b){this.position.x+=this.matrix.n12*b;this.position.y+=this.matrix.n22*b;this.position.z+=this.matrix.n32*b};this.translateZ=function(b){this.position.x-=this.matrix.n13*b;this.position.y-=
M
Mr.doob 已提交
407
this.matrix.n23*b;this.position.z-=this.matrix.n33*b};this.rotateHorizontally=function(b){g.set(this.matrix.n11,this.matrix.n21,this.matrix.n31);g.multiplyScalar(b);this.forward.subSelf(g);this.forward.normalize()};this.rotateVertically=function(b){k.set(this.matrix.n12,this.matrix.n22,this.matrix.n32);k.multiplyScalar(b);this.forward.addSelf(k);this.forward.normalize()};this.domElement.addEventListener("contextmenu",function(b){b.preventDefault()},!1);this.domElement.addEventListener("mousemove",
408 409
function(b){u=(b.clientX-B)/window.innerWidth;w=(b.clientY-A)/window.innerHeight},!1);this.domElement.addEventListener("mousedown",function(b){b.preventDefault();b.stopPropagation();switch(b.button){case 0:o=1;break;case 2:o=-1}},!1);this.domElement.addEventListener("mouseup",function(b){b.preventDefault();b.stopPropagation();switch(b.button){case 0:o=0;break;case 2:o=0}},!1);this.domElement.addEventListener("keydown",function(b){switch(b.keyCode){case 38:case 87:o=1;break;case 37:case 65:t=-1;break;
case 40:case 83:o=-1;break;case 39:case 68:t=1;break;case 81:n=!0;p=1;break;case 69:n=!0;p=-1;break;case 82:v=1;break;case 70:v=-1}},!1);this.domElement.addEventListener("keyup",function(b){switch(b.keyCode){case 38:case 87:o=0;break;case 37:case 65:t=0;break;case 40:case 83:o=0;break;case 39:case 68:t=0;break;case 81:n=!1;break;case 69:n=!1;break;case 82:v=0;break;case 70:v=0}},!1)};THREE.RollCamera.prototype=new THREE.Camera;THREE.RollCamera.prototype.constructor=THREE.RollCamera;
410
THREE.RollCamera.prototype.supr=THREE.Camera.prototype;
M
Mr.doob 已提交
411
THREE.TrackballCamera=function(b){function c(b,e){return function(){e.apply(b,arguments)}}b=b||{};THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.domElement=b.domElement||document;this.screen=b.screen||{width:window.innerWidth,height:window.innerHeight,offsetLeft:0,offsetTop:0};this.radius=b.radius||(this.screen.width+this.screen.height)/4;this.rotateSpeed=b.rotateSpeed||1;this.zoomSpeed=b.zoomSpeed||1.2;this.panSpeed=b.panSpeed||0.3;this.noZoom=b.noZoom||!1;this.noPan=b.noPan||
412
!1;this.staticMoving=b.staticMoving||!1;this.dynamicDampingFactor=b.dynamicDampingFactor||0.2;this.minDistance=b.minDistance||0;this.maxDistance=b.maxDistance||Infinity;this.keys=b.keys||[65,83,68];this.useTarget=!0;var e=!1,f=this.STATE.NONE,g=new THREE.Vector3,k=new THREE.Vector3,h=new THREE.Vector3,m=new THREE.Vector2,n=new THREE.Vector2,p=new THREE.Vector2,o=new THREE.Vector2;this.handleEvent=function(b){if(typeof this[b.type]=="function")this[b.type](b)};this.getMouseOnScreen=function(b,e){return new THREE.Vector2((b-
M
Mr.doob 已提交
413
this.screen.offsetLeft)/this.radius*0.5,(e-this.screen.offsetTop)/this.radius*0.5)};this.getMouseProjectionOnBall=function(b,e){var c=new THREE.Vector3((b-this.screen.width*0.5-this.screen.offsetLeft)/this.radius,(this.screen.height*0.5+this.screen.offsetTop-e)/this.radius,0),f=c.length();f>1?c.normalize():c.z=Math.sqrt(1-f*f);g=this.position.clone().subSelf(this.target.position);f=this.up.clone().setLength(c.y);f.addSelf(this.up.clone().crossSelf(g).setLength(c.x));f.addSelf(g.setLength(c.z));return f};
M
Mr.doob 已提交
414
this.rotateCamera=function(){var b=Math.acos(k.dot(h)/k.length()/h.length());if(b){var e=(new THREE.Vector3).cross(k,h).normalize(),c=new THREE.Quaternion;b*=this.rotateSpeed;c.setFromAxisAngle(e,-b);c.multiplyVector3(g);c.multiplyVector3(this.up);c.multiplyVector3(h);this.staticMoving?k=h:(c.setFromAxisAngle(e,b*(this.dynamicDampingFactor-1)),c.multiplyVector3(k))}};this.zoomCamera=function(){var b=1+(n.y-m.y)*this.zoomSpeed;b!==1&&b>0&&(g.multiplyScalar(b),this.staticMoving?m=n:m.y+=(n.y-m.y)*this.dynamicDampingFactor)};
415
this.panCamera=function(){var b=o.clone().subSelf(p);if(b.lengthSq()){b.multiplyScalar(g.length()*this.panSpeed);var e=g.clone().crossSelf(this.up).setLength(b.x);e.addSelf(this.up.clone().setLength(b.y));this.position.addSelf(e);this.target.position.addSelf(e);this.staticMoving?p=o:p.addSelf(b.sub(o,p).multiplyScalar(this.dynamicDampingFactor))}};this.checkDistances=function(){if(!this.noZoom||!this.noPan)this.position.lengthSq()>this.maxDistance*this.maxDistance&&this.position.setLength(this.maxDistance),
M
Mr.doob 已提交
416
g.lengthSq()<this.minDistance*this.minDistance&&this.position.add(this.target.position,g.setLength(this.minDistance))};this.update=function(b,e,c){g=this.position.clone().subSelf(this.target.position);this.rotateCamera();this.noZoom||this.zoomCamera();this.noPan||this.panCamera();this.position.add(this.target.position,g);this.checkDistances();this.supr.update.call(this,b,e,c)};this.domElement.addEventListener("contextmenu",function(b){b.preventDefault()},!1);this.domElement.addEventListener("mousemove",
417 418
c(this,function(b){e&&(k=h=this.getMouseProjectionOnBall(b.clientX,b.clientY),m=n=this.getMouseOnScreen(b.clientX,b.clientY),p=o=this.getMouseOnScreen(b.clientX,b.clientY),e=!1);f!==this.STATE.NONE&&(f===this.STATE.ROTATE?h=this.getMouseProjectionOnBall(b.clientX,b.clientY):f===this.STATE.ZOOM&&!this.noZoom?n=this.getMouseOnScreen(b.clientX,b.clientY):f===this.STATE.PAN&&!this.noPan&&(o=this.getMouseOnScreen(b.clientX,b.clientY)))}),!1);this.domElement.addEventListener("mousedown",c(this,function(b){b.preventDefault();
b.stopPropagation();if(f===this.STATE.NONE)f=b.button,f===this.STATE.ROTATE?k=h=this.getMouseProjectionOnBall(b.clientX,b.clientY):f===this.STATE.ZOOM&&!this.noZoom?m=n=this.getMouseOnScreen(b.clientX,b.clientY):this.noPan||(p=o=this.getMouseOnScreen(b.clientX,b.clientY))}),!1);this.domElement.addEventListener("mouseup",c(this,function(b){b.preventDefault();b.stopPropagation();f=this.STATE.NONE}),!1);window.addEventListener("keydown",c(this,function(b){if(f===this.STATE.NONE){if(b.keyCode===this.keys[this.STATE.ROTATE])f=
M
Mr.doob 已提交
419
this.STATE.ROTATE;else if(b.keyCode===this.keys[this.STATE.ZOOM]&&!this.noZoom)f=this.STATE.ZOOM;else if(b.keyCode===this.keys[this.STATE.PAN]&&!this.noPan)f=this.STATE.PAN;f!==this.STATE.NONE&&(e=!0)}}),!1);window.addEventListener("keyup",c(this,function(){if(f!==this.STATE.NONE)f=this.STATE.NONE}),!1)};THREE.TrackballCamera.prototype=new THREE.Camera;THREE.TrackballCamera.prototype.constructor=THREE.TrackballCamera;THREE.TrackballCamera.prototype.supr=THREE.Camera.prototype;
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
THREE.TrackballCamera.prototype.STATE={NONE:-1,ROTATE:0,ZOOM:1,PAN:2};THREE.QuakeCamera=THREE.FirstPersonCamera;THREE.Path=function(b){this.actions=[];b&&this.fromPoints(b)};THREE.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_TO:"cSplineTo"};THREE.Path.prototype.fromPoints=function(b){var c=0,e=b.length;this.moveTo(b[0].x,b[0].y);for(c=1;c<e;c++)this.lineTo(b[c].x,b[c].y)};
THREE.Path.prototype.moveTo=function(){var b=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.MOVE_TO,args:b})};THREE.Path.prototype.lineTo=function(){var b=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.LINE_TO,args:b})};THREE.Path.prototype.quadraticCurveTo=function(){var b=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.QUADRATIC_CURVE_TO,args:b})};
THREE.Path.prototype.bezierCurveTo=function(){var b=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.BEZIER_CURVE_TO,args:b})};
THREE.Path.prototype.getPoints=function(b){var b=b||12,c=[],e,f,g,k,h,m,n,p,o,t,v,u,w;e=0;for(f=this.actions.length;e<f;e++)switch(g=this.actions[e],k=g.action,h=g.args,k){case THREE.PathActions.LINE_TO:c.push(new THREE.Vector2(h[0],h[1]));break;case THREE.PathActions.QUADRATIC_CURVE_TO:k=h[2];g=h[3];n=h[0];p=h[1];c.length>0?(t=c[c.length-1],o=t.x,t=t.y):(t=this.actions[e-1].args,o=t[t.length-2],t=t[t.length-1]);for(v=1;v<=b;v++)u=v/b,w=THREE.FontUtils.b2(u,o,n,k),u=THREE.FontUtils.b2(u,t,p,g),c.push(new THREE.Vector2(w,
u));break;case THREE.PathActions.BEZIER_CURVE_TO:k=h[4];g=h[5];n=h[0];p=h[1];m=h[2];h=h[3];c.length>0?(t=c[c.length-1],o=t.x,t=t.y):(t=this.actions[e-1].args,o=t[t.length-2],t=t[t.length-1]);for(v=1;v<=b;v++)u=v/b,w=THREE.FontUtils.b3(u,o,n,m,k),u=THREE.FontUtils.b3(u,t,p,h,g),c.push(new THREE.Vector2(w,u))}return c};
THREE.Path.prototype.getMinAndMax=function(){var b=this.getPoints(),c,e,f,g;c=e=Number.NEGATIVE_INFINITY;f=g=Number.POSITIVE_INFINITY;var k,h,m;h=0;for(m=b.length;h<m;h++){k=b[h];if(k.x>c)c=k.x;else if(k.x<f)f=k.x;if(k.y>e)e=k.y;else if(k.y<e)g=k.y}return{minX:f,minY:g,maxX:c,maxY:e}};
THREE.Path.prototype.debug=function(b){b||(b=document.createElement("canvas"),b.setAttribute("width",200),b.setAttribute("height",200),document.body.appendChild(b));b=b.getContext("2d");b.fillStyle="white";b.fillRect(0,0,200,200);b.strokeStyle="black";b.beginPath();var c,e,f,g;c=0;for(e=this.actions.length;c<e;c++)f=this.actions[c],g=f.args,f=f.action,b[f].apply(b,g);b.stroke();b.closePath();b.strokeStyle="red";f=this.getPoints();c=0;for(e=f.length;c<e;c++)g=f[c],b.beginPath(),b.arc(g.x,g.y,1.5,0,
Math.PI*2,!1),b.stroke(),b.closePath()};THREE.Shape=function(){THREE.Path.apply(this,arguments);this.holes=[]};THREE.Shape.prototype=new THREE.Path;THREE.Shape.prototype.constructor=THREE.Path;THREE.Shape.prototype.triangulate=function(){return THREE.FontUtils.Triangulate(this.getPoints(),!0)};THREE.Shape.prototype.extrude=function(b){return new THREE.ExtrudeGeometry(this,b)};
THREE.CubeGeometry=function(b,c,e,f,g,k,h,m,n){function p(b,e,c,h,m,n,p,t){var u,v,w=f||1,B=g||1,K=m/2,ea=n/2,j=o.vertices.length;if(b=="x"&&e=="y"||b=="y"&&e=="x")u="z";else if(b=="x"&&e=="z"||b=="z"&&e=="x")u="y",B=k||1;else if(b=="z"&&e=="y"||b=="y"&&e=="z")u="x",w=k||1;var ca=w+1,T=B+1;m/=w;var Z=n/B;for(v=0;v<T;v++)for(n=0;n<ca;n++){var N=new THREE.Vector3;N[b]=(n*m-K)*c;N[e]=(v*Z-ea)*h;N[u]=p;o.vertices.push(new THREE.Vertex(N))}for(v=0;v<B;v++)for(n=0;n<w;n++)o.faces.push(new THREE.Face4(n+
ca*v+j,n+ca*(v+1)+j,n+1+ca*(v+1)+j,n+1+ca*v+j,null,null,t)),o.faceVertexUvs[0].push([new THREE.UV(n/w,v/B),new THREE.UV(n/w,(v+1)/B),new THREE.UV((n+1)/w,(v+1)/B),new THREE.UV((n+1)/w,v/B)])}THREE.Geometry.call(this);var o=this,t=b/2,v=c/2,u=e/2,m=m?-1:1;if(h!==void 0)if(h instanceof Array)this.materials=h;else{this.materials=[];for(var w=0;w<6;w++)this.materials.push([h])}else this.materials=[];this.sides={px:!0,nx:!0,py:!0,ny:!0,pz:!0,nz:!0};if(n!=void 0)for(var B in n)this.sides[B]!=void 0&&(this.sides[B]=
n[B]);this.sides.px&&p("z","y",1*m,-1,e,c,-t,this.materials[0]);this.sides.nx&&p("z","y",-1*m,-1,e,c,t,this.materials[1]);this.sides.py&&p("x","z",1*m,1,b,e,v,this.materials[2]);this.sides.ny&&p("x","z",1*m,-1,b,e,-v,this.materials[3]);this.sides.pz&&p("x","y",1*m,-1,b,c,u,this.materials[4]);this.sides.nz&&p("x","y",-1*m,-1,b,c,-u,this.materials[5]);(function(){for(var b=[],e=[],c=0,f=o.vertices.length;c<f;c++){for(var h=o.vertices[c],g=!1,k=0,m=b.length;k<m;k++){var n=b[k];if(h.position.x==n.position.x&&
h.position.y==n.position.y&&h.position.z==n.position.z){e[c]=k;g=!0;break}}if(!g)e[c]=b.length,b.push(new THREE.Vertex(h.position.clone()))}c=0;for(f=o.faces.length;c<f;c++)h=o.faces[c],h.a=e[h.a],h.b=e[h.b],h.c=e[h.c],h.d=e[h.d];o.vertices=b})();this.computeCentroids();this.computeFaceNormals()};THREE.CubeGeometry.prototype=new THREE.Geometry;THREE.CubeGeometry.prototype.constructor=THREE.CubeGeometry;
THREE.CylinderGeometry=function(b,c,e,f,g,k){function h(b,e,c){m.vertices.push(new THREE.Vertex(new THREE.Vector3(b,e,c)))}THREE.Geometry.call(this);var m=this,n,p=Math.PI*2,o=f/2;for(n=0;n<b;n++)h(Math.sin(p*n/b)*c,Math.cos(p*n/b)*c,-o);for(n=0;n<b;n++)h(Math.sin(p*n/b)*e,Math.cos(p*n/b)*e,o);for(n=0;n<b;n++)m.faces.push(new THREE.Face4(n,n+b,b+(n+1)%b,(n+1)%b));if(e>0){h(0,0,-o-(k||0));for(n=b;n<b+b/2;n++)m.faces.push(new THREE.Face4(2*b,(2*n-2*b)%b,(2*n-2*b+1)%b,(2*n-2*b+2)%b))}if(c>0){h(0,0,o+
(g||0));for(n=b+b/2;n<2*b;n++)m.faces.push(new THREE.Face4(2*b+1,(2*n-2*b+2)%b+b,(2*n-2*b+1)%b+b,(2*n-2*b)%b+b))}n=0;for(b=this.faces.length;n<b;n++){var c=[],e=this.faces[n],g=this.vertices[e.a],k=this.vertices[e.b],o=this.vertices[e.c],t=this.vertices[e.d];c.push(new THREE.UV(0.5+Math.atan2(g.position.x,g.position.y)/p,0.5+g.position.z/f));c.push(new THREE.UV(0.5+Math.atan2(k.position.x,k.position.y)/p,0.5+k.position.z/f));c.push(new THREE.UV(0.5+Math.atan2(o.position.x,o.position.y)/p,0.5+o.position.z/
f));e instanceof THREE.Face4&&c.push(new THREE.UV(0.5+Math.atan2(t.position.x,t.position.y)/p,0.5+t.position.z/f));this.faceVertexUvs[0].push(c)}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=new THREE.Geometry;THREE.CylinderGeometry.prototype.constructor=THREE.CylinderGeometry;
THREE.ExtrudeGeometry=function(b,c){function e(b,e,c){n.vertices.push(new THREE.Vertex(new THREE.Vector3(b,e,c)))}var f=c.amount!==void 0?c.amount:100,g=c.bezelThickness!==void 0?c.bezelThickness:10,k=c.bezelEnabled!==void 0?c.bezelEnabled:!1;THREE.Geometry.call(this);var h=b.getPoints(),m=b.triangulate(),n=this,p=[],o,t,v=h.length,u=m.length,w=p.length;for(o=0;o<v;o++)t=h[o],e(t.x,t.y,0);for(o=0;o<v;o++)t=h[o],e(t.x,t.y,f);if(k){for(o=0;o<w;o++)k=p[o],e(k.x,k.y,g);for(o=0;o<w;o++)k=p[o],e(k.x,k.y,
f-g)}for(o=0;o<u;o++)f=m[o],n.faces.push(new THREE.Face3(f[2],f[1],f[0]));for(o=0;o<u;o++)f=m[o],n.faces.push(new THREE.Face3(f[0]+v,f[1]+v,f[2]+v));h.push(h[0]);for(o=h.length;--o>0;){for(m=0;m<v;m++)if(h[m].equals(h[o]))break;for(u=0;u<v;u++)if(h[u].equals(h[o-1]))break;n.faces.push(new THREE.Face4(m,u,u+v,m+v))}this.computeCentroids();this.computeFaceNormals()};THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
M
Mr.doob 已提交
437
THREE.IcosahedronGeometry=function(b){function c(b,e,c){var f=Math.sqrt(b*b+e*e+c*c);return g.vertices.push(new THREE.Vertex(new THREE.Vector3(b/f,e/f,c/f)))-1}function e(b,e,c,f){f.faces.push(new THREE.Face3(b,e,c))}function f(b,e){var f=g.vertices[b].position,h=g.vertices[e].position;return c((f.x+h.x)/2,(f.y+h.y)/2,(f.z+h.z)/2)}var g=this,k=new THREE.Geometry,h;this.subdivisions=b||0;THREE.Geometry.call(this);b=(1+Math.sqrt(5))/2;c(-1,b,0);c(1,b,0);c(-1,-b,0);c(1,-b,0);c(0,-1,b);c(0,1,b);c(0,-1,
438 439
-b);c(0,1,-b);c(b,0,-1);c(b,0,1);c(-b,0,-1);c(-b,0,1);e(0,11,5,k);e(0,5,1,k);e(0,1,7,k);e(0,7,10,k);e(0,10,11,k);e(1,5,9,k);e(5,11,4,k);e(11,10,2,k);e(10,7,6,k);e(7,1,8,k);e(3,9,4,k);e(3,4,2,k);e(3,2,6,k);e(3,6,8,k);e(3,8,9,k);e(4,9,5,k);e(2,4,11,k);e(6,2,10,k);e(8,6,7,k);e(9,8,1,k);for(b=0;b<this.subdivisions;b++){h=new THREE.Geometry;for(var m in k.faces){var n=f(k.faces[m].a,k.faces[m].b),p=f(k.faces[m].b,k.faces[m].c),o=f(k.faces[m].c,k.faces[m].a);e(k.faces[m].a,n,o,h);e(k.faces[m].b,p,n,h);
e(k.faces[m].c,o,p,h);e(n,p,o,h)}k.faces=h.faces}g.faces=k.faces;delete k;delete h;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.IcosahedronGeometry.prototype=new THREE.Geometry;THREE.IcosahedronGeometry.prototype.constructor=THREE.IcosahedronGeometry;
A
alteredq 已提交
440
THREE.LatheGeometry=function(b,c,e){THREE.Geometry.call(this);this.steps=c||12;this.angle=e||2*Math.PI;for(var c=this.angle/this.steps,e=[],f=[],g=[],k=[],h=(new THREE.Matrix4).setRotationZ(c),m=0;m<b.length;m++)this.vertices.push(new THREE.Vertex(b[m])),e[m]=b[m].clone(),f[m]=this.vertices.length-1;for(var n=0;n<=this.angle+0.0010;n+=c){for(m=0;m<e.length;m++)n<this.angle?(e[m]=h.multiplyVector3(e[m].clone()),this.vertices.push(new THREE.Vertex(e[m])),g[m]=this.vertices.length-1):g=k;n==0&&(k=f);
M
Mr.doob 已提交
441
for(m=0;m<f.length-1;m++)this.faces.push(new THREE.Face4(g[m],g[m+1],f[m+1],f[m])),this.faceVertexUvs[0].push([new THREE.UV(1-n/this.angle,m/b.length),new THREE.UV(1-n/this.angle,(m+1)/b.length),new THREE.UV(1-(n-c)/this.angle,(m+1)/b.length),new THREE.UV(1-(n-c)/this.angle,m/b.length)]);f=g;g=[]}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=new THREE.Geometry;THREE.LatheGeometry.prototype.constructor=THREE.LatheGeometry;
442
THREE.PlaneGeometry=function(b,c,e,f){THREE.Geometry.call(this);var g,k=b/2,h=c/2,e=e||1,f=f||1,m=e+1,n=f+1;b/=e;var p=c/f;for(g=0;g<n;g++)for(c=0;c<m;c++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(c*b-k,-(g*p-h),0)));for(g=0;g<f;g++)for(c=0;c<e;c++)this.faces.push(new THREE.Face4(c+m*g,c+m*(g+1),c+1+m*(g+1),c+1+m*g)),this.faceVertexUvs[0].push([new THREE.UV(c/e,g/f),new THREE.UV(c/e,(g+1)/f),new THREE.UV((c+1)/e,(g+1)/f),new THREE.UV((c+1)/e,g/f)]);this.computeCentroids();this.computeFaceNormals()};
443
THREE.PlaneGeometry.prototype=new THREE.Geometry;THREE.PlaneGeometry.prototype.constructor=THREE.PlaneGeometry;
444 445 446
THREE.SphereGeometry=function(b,c,e){THREE.Geometry.call(this);for(var b=b||50,f,g=Math.PI,k=Math.max(3,c||8),h=Math.max(2,e||6),c=[],e=0;e<h+1;e++){f=e/h;var m=b*Math.cos(f*g),n=b*Math.sin(f*g),p=[],o=0;for(f=0;f<k;f++){var t=2*f/k,v=n*Math.sin(t*g),t=n*Math.cos(t*g);(e==0||e==h)&&f>0||(o=this.vertices.push(new THREE.Vertex(new THREE.Vector3(t,m,v)))-1);p.push(o)}c.push(p)}for(var u,w,B,g=c.length,e=0;e<g;e++)if(k=c[e].length,e>0)for(f=0;f<k;f++){p=f==k-1;h=c[e][p?0:f+1];m=c[e][p?k-1:f];n=c[e-1][p?
k-1:f];p=c[e-1][p?0:f+1];v=e/(g-1);u=(e-1)/(g-1);w=(f+1)/k;var t=f/k,o=new THREE.UV(1-w,v),v=new THREE.UV(1-t,v),t=new THREE.UV(1-t,u),A=new THREE.UV(1-w,u);e<c.length-1&&(u=this.vertices[h].position.clone(),w=this.vertices[m].position.clone(),B=this.vertices[n].position.clone(),u.normalize(),w.normalize(),B.normalize(),this.faces.push(new THREE.Face3(h,m,n,[new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(B.x,B.y,B.z)])),this.faceVertexUvs[0].push([o,v,t]));e>1&&(u=
this.vertices[h].position.clone(),w=this.vertices[n].position.clone(),B=this.vertices[p].position.clone(),u.normalize(),w.normalize(),B.normalize(),this.faces.push(new THREE.Face3(h,n,p,[new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(B.x,B.y,B.z)])),this.faceVertexUvs[0].push([o,t,A]))}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:b}};THREE.SphereGeometry.prototype=new THREE.Geometry;
447
THREE.SphereGeometry.prototype.constructor=THREE.SphereGeometry;THREE.TextGeometry=function(b,c){THREE.Geometry.call(this);this.parameters=c||{};this.set(b)};THREE.TextGeometry.prototype=new THREE.Geometry;THREE.TextGeometry.prototype.constructor=THREE.TextGeometry;
448 449 450
THREE.TextGeometry.prototype.set=function(b,c){function e(b,e,c){w.vertices.push(new THREE.Vertex(new THREE.Vector3(b,e,c)))}function f(b,e,c,f){w.faces.push(new THREE.Face4(b,e,c,f))}this.text=b;var c=c||this.parameters,g=c.height!==void 0?c.height:50,k=c.curveSegments!==void 0?c.curveSegments:4,h=c.font!==void 0?c.font:"helvetiker",m=c.weight!==void 0?c.weight:"normal",n=c.style!==void 0?c.style:"normal",p=c.bezelThickness!==void 0?c.bezelThickness:10,o=c.bezelSize!==void 0?c.bezelSize:8,t=c.bezelEnabled!==
void 0?c.bezelEnabled:!1;THREE.FontUtils.size=c.size!==void 0?c.size:100;THREE.FontUtils.divisions=k;THREE.FontUtils.face=h;THREE.FontUtils.weight=m;THREE.FontUtils.style=n;THREE.FontUtils.bezelSize=o;var m=THREE.FontUtils.drawText(b),k=m.points,v=m.faces,h=m.contour,u=m.bezel,w=this;w.vertices=[];w.faces=[];for(var B,n=k.length,A=v.length,o=u.length,m=0;m<n;m++)B=k[m],e(B.x,B.y,0);for(m=0;m<n;m++)B=k[m],e(B.x,B.y,g);if(t){for(m=0;m<o;m++)B=u[m],e(B.x,B.y,p);for(m=0;m<o;m++)B=u[m],e(B.x,B.y,g-p)}for(m=
0;m<A;m++)g=v[m],w.faces.push(new THREE.Face3(g[2],g[1],g[0]));for(m=0;m<A;m++)g=v[m],w.faces.push(new THREE.Face3(g[0]+n,g[1]+n,g[2]+n));var y;if(t)for(m=u.length;--m>0;){if(y){if(y.equals(h[m])){y=null;continue}}else y=h[m];p=n*2+m;v=p-1;f(p,v,v+o,p+o);for(t=0;t<n;t++)if(k[t].equals(h[m]))break;for(g=0;g<n;g++)if(k[g].equals(h[m-1]))break;f(t,g,v,p);f(p+o,v+o,g+n,t+n)}else for(m=h.length;--m>0;){if(y){if(y.equals(h[m])){y=null;continue}}else y=h[m];for(t=0;t<n;t++)if(k[t].equals(h[m]))break;for(g=
M
Mr.doob 已提交
451
0;g<n;g++)if(k[g].equals(h[m-1]))break;f(t,g,g+n,t+n)}this.computeCentroids();this.computeFaceNormals()};
452
THREE.FontUtils={faces:{},face:"helvetiker",weight:"normal",style:"normal",size:150,divisions:10,getFace:function(){return this.faces[this.face][this.weight][this.style]},loadFace:function(b){var c=b.familyName.toLowerCase();this.faces[c]=this.faces[c]||{};this.faces[c][b.cssFontWeight]=this.faces[c][b.cssFontWeight]||{};this.faces[c][b.cssFontWeight][b.cssFontStyle]=b;return this.faces[c][b.cssFontWeight][b.cssFontStyle]=b},extractPoints:function(b,c){if(b.length<3)return console.log("not valid polygon"),
453 454 455 456 457 458 459 460 461 462
{points:b,faces:[]};for(var e,f,g,k,h,m=[],n=0;n<c.length;n++){h=c[n];k=[];for(e=0;e<h.length;e++)f=h[e],k.push(f.x+","+f.y);var p;e=k.slice(1).indexOf(k[0]);var o=this.Triangulate.area(h.slice(0,e+1))<0;f=[];for(e=-1;e<k.length;){p=e+1;e=k[p];e=k.slice(p+1).indexOf(e)+p;if(e<=p)break;var t=h.slice(p,e+1);o?this.Triangulate.area(t)<0?(p>0&&m.push({shape:g,holes:f}),g=t,f=[]):f.push(t):this.Triangulate.area(t)<0?(m.push({shape:t,holes:f}),f=[]):f.push(t);e++}o&&m.push({shape:g,holes:f})}var v,u,w,
B,A,y;k=[];for(h=0;h<m.length;h++){n=m[h];g=n.shape;f=n.holes;for(p=0;p<f.length;p++){o=f[p];w=Number.POSITIVE_INFINITY;for(t=0;t<o.length;t++){A=o[t];for(e=0;e<g.length;e++)B=g[e],B=A.distanceTo(B),B<w&&(w=B,v=t,u=e)}e=u-1>=0?u-1:g.length-1;var t=v-1>=0?v-1:o.length-1,G=[];G.push(o[v]);G.push(g[u]);G.push(g[e]);w=this.Triangulate.area(G);var z=[];z.push(o[v]);z.push(o[t]);z.push(g[u]);A=this.Triangulate.area(z);B=u;y=v;u+=1;v+=-1;u<0&&(u+=g.length);u%=g.length;v<0&&(v+=o.length);v%=g.length;e=u-
1>=0?u-1:g.length-1;t=v-1>=0?v-1:o.length-1;G=[];G.push(o[v]);G.push(g[u]);G.push(g[e]);G=this.Triangulate.area(G);z=[];z.push(o[v]);z.push(o[t]);z.push(g[u]);z=this.Triangulate.area(z);w+A>G+z&&(u=B,v=y,u<0&&(u+=g.length),u%=g.length,v<0&&(v+=o.length),v%=g.length,e=u-1>=0?u-1:g.length-1,t=v-1>=0?v-1:o.length-1);w=g.slice(0,u);A=g.slice(u);B=o.slice(v);y=o.slice(0,v);k.push(o[v]);k.push(g[u]);k.push(g[e]);k.push(o[v]);k.push(o[t]);k.push(g[u]);g=w.concat(B).concat(y).concat(A)}n.shape=g}v=[];u=[];
for(h=p=0;h<m.length;h++){n=m[h];g=n.shape;v=v.concat(g);o=THREE.FontUtils.Triangulate(g,!0);for(f=0;f<o.length;f++)n=o[f],n[0]+=p,n[1]+=p,n[2]+=p;u=u.concat(o);p+=g.length}var C;for(f=0;f<k.length/3;f++){n=[];for(m=0;m<3;m++){h=!1;for(g=0;g<v.length&&!h;g++)C=f*3+m,v[g].equals(k[C])&&(n.push(g),h=!0);h||(v.push(k[C]),n.push(v.length-1),console.log("not found"))}u.push(n)}return{points:v,faces:u}},drawText:function(b){var c=[],e=[],f,g=this.getFace(),k=this.size/g.resolution,h=0;f=String(b).split("");
for(var m=f.length,n=[],b=0;b<m;b++){var p=this.extractGlyphPoints(f[b],g,k,h);h+=p.offset;c.push(p.points);e=e.concat(p.points);n.push(p.path)}b=h/2;for(f=0;f<e.length;f++)e[f].x-=b;c=this.extractPoints(e,c);c.contour=e;g=[];k=[];f=[];for(var h=[],m=new THREE.Vector2,o,b=e.length;--b>=0;){if(o){if(o.equals(e[b])){o=null;n=this.Triangulate.area(f)>0;h.push(n);k.push(m.divideScalar(f.length));f=[];m=new THREE.Vector2;continue}}else o=e[b];m.addSelf(e[b]);f.push(e[b])}b=e.length;for(f=0;--b>=0;)n=e[b],
m=k[f],n=n.clone().subSelf(m),p=this.bezelSize/n.length(),h[f]?p+=1:p=1-p,p=n.multiplyScalar(p).addSelf(m),g.unshift(p),o?o.equals(e[b])&&(o=null,f++):o=e[b];c.bezel=g;return c},b2p0:function(b,c){var e=1-b;return e*e*c},b2p1:function(b,c){return 2*(1-b)*b*c},b2p2:function(b,c){return b*b*c},b2:function(b,c,e,f){return this.b2p0(b,c)+this.b2p1(b,e)+this.b2p2(b,f)},b3p0:function(b,c){var e=1-b;return e*e*e*c},b3p1:function(b,c){var e=1-b;return 3*e*e*b*c},b3p2:function(b,c){return 3*(1-b)*b*b*c},b3p3:function(b,
c){return b*b*b*c},b3:function(b,c,e,f,g){return this.b3p0(b,c)+this.b3p1(b,e)+this.b3p2(b,f)+this.b3p3(b,g)},extractGlyphPoints:function(b,c,e,f){var g=[],k=new THREE.Path,h,m,n,p,o,t,v,u,w,B,A=c.glyphs[b]||c.glyphs[ctxt.options.fallbackCharacter];if(A){if(A.o){c=A._cachedOutline||(A._cachedOutline=A.o.split(" "));n=c.length;for(b=0;b<n;)switch(m=c[b++],m){case "m":m=c[b++]*e+f;p=c[b++]*e;g.push(new THREE.Vector2(m,p));k.moveTo(m,p);break;case "l":m=c[b++]*e+f;p=c[b++]*e;g.push(new THREE.Vector2(m,
p));k.lineTo(m,p);break;case "q":m=c[b++]*e+f;p=c[b++]*e;v=c[b++]*e+f;u=c[b++]*e;k.quadraticCurveTo(v,u,m,p);if(h=g[g.length-1]){o=h.x;t=h.y;h=1;for(divisions=this.divisions;h<=divisions;h++){var y=h/divisions,G=THREE.FontUtils.b2(y,o,v,m),y=THREE.FontUtils.b2(y,t,u,p);g.push(new THREE.Vector2(G,y))}}break;case "b":if(m=c[b++]*e+f,p=c[b++]*e,v=c[b++]*e+f,u=c[b++]*-e,w=c[b++]*e+f,B=c[b++]*-e,k.quadraticCurveTo(m,p,v,u,w,B),h=g[g.length-1]){o=h.x;t=h.y;h=1;for(divisions=this.divisions;h<=divisions;h++)y=
h/divisions,G=THREE.FontUtils.b3(y,o,v,w,m),y=THREE.FontUtils.b3(y,t,u,B,p),g.push(new THREE.Vector2(G,y))}}}k.debug(document.getElementById("boo"));console.log(k);return{offset:A.ha*e,points:g,path:k}}}};
(function(b){var c=function(b){for(var c=b.length,g=0,k=c-1,h=0;h<c;k=h++)g+=b[k].x*b[h].y-b[h].x*b[k].y;return g*0.5};b.Triangulate=function(b,f){var g=b.length;if(g<3)return null;var k=[],h=[],m=[],n,p,o;if(c(b)>0)for(p=0;p<g;p++)h[p]=p;else for(p=0;p<g;p++)h[p]=g-1-p;var t=2*g;for(p=g-1;g>2;){if(t--<=0){console.log("Warning, unable to triangulate polygon!");if(f)return m;return k}n=p;g<=n&&(n=0);p=n+1;g<=p&&(p=0);o=p+1;g<=o&&(o=0);var v;a:{v=b;var u=n,w=p,B=o,A=g,y=h,G=void 0,z=void 0,C=void 0,
M
Mr.doob 已提交
463
H=void 0,D=void 0,Q=void 0,J=void 0,F=void 0,I=void 0,z=v[y[u]].x,C=v[y[u]].y,H=v[y[w]].x,D=v[y[w]].y,Q=v[y[B]].x,J=v[y[B]].y;if(1.0E-10>(H-z)*(J-C)-(D-C)*(Q-z))v=!1;else{for(G=0;G<A;G++)if(!(G==u||G==w||G==B)){var F=v[y[G]].x,I=v[y[G]].y,S=void 0,K=void 0,ea=void 0,j=void 0,ca=void 0,T=void 0,Z=void 0,N=void 0,da=void 0,X=void 0,aa=void 0,ia=void 0,S=ea=ca=void 0,S=Q-H,K=J-D,ea=z-Q,j=C-J,ca=H-z,T=D-C,Z=F-z,N=I-C,da=F-H,X=I-D,aa=F-Q,ia=I-J,S=S*X-K*da,ca=ca*N-T*Z,ea=ea*ia-j*aa;if(S>=0&&ea>=0&&ca>=
464
0){v=!1;break a}}v=!0}}if(v){t=h[n];v=h[p];u=h[o];k.push(b[t]);k.push(b[v]);k.push(b[u]);m.push([h[n],h[p],h[o]]);n=p;for(o=p+1;o<g;n++,o++)h[n]=h[o];g--;t=2*g}}if(f)return m;return k};b.Triangulate.area=c;return b})(THREE.FontUtils);window._typeface_js={faces:THREE.FontUtils.faces,loadFace:THREE.FontUtils.loadFace};
M
Mr.doob 已提交
465
THREE.TorusGeometry=function(b,c,e,f){THREE.Geometry.call(this);this.radius=b||100;this.tube=c||40;this.segmentsR=e||8;this.segmentsT=f||6;b=[];for(c=0;c<=this.segmentsR;++c)for(e=0;e<=this.segmentsT;++e){var f=e/this.segmentsT*2*Math.PI,g=c/this.segmentsR*2*Math.PI;this.vertices.push(new THREE.Vertex(new THREE.Vector3((this.radius+this.tube*Math.cos(g))*Math.cos(f),(this.radius+this.tube*Math.cos(g))*Math.sin(f),this.tube*Math.sin(g))));b.push([e/this.segmentsT,1-c/this.segmentsR])}for(c=1;c<=this.segmentsR;++c)for(e=
M
Mr.doob 已提交
466
1;e<=this.segmentsT;++e){var f=(this.segmentsT+1)*c+e,g=(this.segmentsT+1)*c+e-1,k=(this.segmentsT+1)*(c-1)+e-1,h=(this.segmentsT+1)*(c-1)+e;this.faces.push(new THREE.Face4(f,g,k,h));this.faceVertexUvs[0].push([new THREE.UV(b[f][0],b[f][1]),new THREE.UV(b[g][0],b[g][1]),new THREE.UV(b[k][0],b[k][1]),new THREE.UV(b[h][0],b[h][1])])}delete b;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.TorusGeometry.prototype=new THREE.Geometry;
467
THREE.TorusGeometry.prototype.constructor=THREE.TorusGeometry;
468
THREE.TorusKnotGeometry=function(b,c,e,f,g,k,h){function m(b,c,e,f,h,g){c=e/f*b;e=Math.cos(c);return new THREE.Vector3(h*(2+e)*0.5*Math.cos(b),h*(2+e)*Math.sin(b)*0.5,g*h*Math.sin(c)*0.5)}THREE.Geometry.call(this);this.radius=b||200;this.tube=c||40;this.segmentsR=e||64;this.segmentsT=f||8;this.p=g||2;this.q=k||3;this.heightScale=h||1;this.grid=Array(this.segmentsR);e=new THREE.Vector3;f=new THREE.Vector3;k=new THREE.Vector3;for(b=0;b<this.segmentsR;++b){this.grid[b]=Array(this.segmentsT);for(c=0;c<
M
Mr.doob 已提交
469
this.segmentsT;++c){var n=b/this.segmentsR*2*this.p*Math.PI,h=c/this.segmentsT*2*Math.PI,g=m(n,h,this.q,this.p,this.radius,this.heightScale),n=m(n+0.01,h,this.q,this.p,this.radius,this.heightScale);e.x=n.x-g.x;e.y=n.y-g.y;e.z=n.z-g.z;f.x=n.x+g.x;f.y=n.y+g.y;f.z=n.z+g.z;k.cross(e,f);f.cross(k,e);k.normalize();f.normalize();n=-this.tube*Math.cos(h);h=this.tube*Math.sin(h);g.x+=n*f.x+h*k.x;g.y+=n*f.y+h*k.y;g.z+=n*f.z+h*k.z;this.grid[b][c]=this.vertices.push(new THREE.Vertex(new THREE.Vector3(g.x,g.y,
470
g.z)))-1}}for(b=0;b<this.segmentsR;++b)for(c=0;c<this.segmentsT;++c){var f=(b+1)%this.segmentsR,k=(c+1)%this.segmentsT,g=this.grid[b][c],e=this.grid[f][c],f=this.grid[f][k],k=this.grid[b][k],h=new THREE.UV(b/this.segmentsR,c/this.segmentsT),n=new THREE.UV((b+1)/this.segmentsR,c/this.segmentsT),p=new THREE.UV((b+1)/this.segmentsR,(c+1)/this.segmentsT),o=new THREE.UV(b/this.segmentsR,(c+1)/this.segmentsT);this.faces.push(new THREE.Face4(g,e,f,k));this.faceVertexUvs[0].push([h,n,p,o])}this.computeCentroids();
471 472
this.computeFaceNormals();this.computeVertexNormals()};THREE.TorusKnotGeometry.prototype=new THREE.Geometry;THREE.TorusKnotGeometry.prototype.constructor=THREE.TorusKnotGeometry;THREE.Loader=function(b){this.statusDomElement=(this.showStatus=b)?THREE.Loader.prototype.addStatusElement():null;this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){}};
THREE.Loader.prototype={addStatusElement:function(){var b=document.createElement("div");b.style.position="absolute";b.style.right="0px";b.style.top="0px";b.style.fontSize="0.8em";b.style.textAlign="left";b.style.background="rgba(0,0,0,0.25)";b.style.color="#fff";b.style.width="120px";b.style.padding="0.5em 0.5em 0.5em 0.5em";b.style.zIndex=1E3;b.innerHTML="Loading ...";return b},updateProgress:function(b){var c="Loaded ";c+=b.total?(100*b.loaded/b.total).toFixed(0)+"%":(b.loaded/1E3).toFixed(2)+" KB";
M
Mr.doob 已提交
473 474
this.statusDomElement.innerHTML=c},extractUrlbase:function(b){b=b.split("/");b.pop();return b.join("/")},init_materials:function(b,c,e){b.materials=[];for(var f=0;f<c.length;++f)b.materials[f]=[THREE.Loader.prototype.createMaterial(c[f],e)]},hasNormals:function(b){var c,e,f=b.materials.length;for(e=0;e<f;e++)if(c=b.materials[e][0],c instanceof THREE.MeshShaderMaterial)return!0;return!1},createMaterial:function(b,c){function e(b){b=Math.log(b)/Math.LN2;return Math.floor(b)==b}function f(b,c){var f=
new Image;f.onload=function(){if(!e(this.width)||!e(this.height)){var c=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),f=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));b.image.width=c;b.image.height=f;b.image.getContext("2d").drawImage(this,0,0,c,f)}else b.image=this;b.needsUpdate=!0};f.src=c}function g(b,e,h,g,k,m){var n=document.createElement("canvas");b[e]=new THREE.Texture(n);b[e].sourceFile=h;if(g){b[e].repeat.set(g[0],g[1]);if(g[0]!=1)b[e].wrapS=THREE.RepeatWrapping;if(g[1]!=
M
Mr.doob 已提交
475
1)b[e].wrapT=THREE.RepeatWrapping}k&&b[e].offset.set(k[0],k[1]);if(m){g={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(g[m[0]]!==void 0)b[e].wrapS=g[m[0]];if(g[m[1]]!==void 0)b[e].wrapT=g[m[1]]}f(b[e],c+"/"+h)}function k(b){return(b[0]*255<<16)+(b[1]*255<<8)+b[2]*255}var h,m,n;m="MeshLambertMaterial";h={color:15658734,opacity:1,map:null,lightMap:null,normalMap:null,wireframe:b.wireframe};b.shading&&(b.shading=="Phong"?m="MeshPhongMaterial":b.shading=="Basic"&&(m="MeshBasicMaterial"));
M
Mr.doob 已提交
476 477
if(b.blending)if(b.blending=="Additive")h.blending=THREE.AdditiveBlending;else if(b.blending=="Subtractive")h.blending=THREE.SubtractiveBlending;else if(b.blending=="Multiply")h.blending=THREE.MultiplyBlending;if(b.transparent!==void 0||b.opacity<1)h.transparent=b.transparent;if(b.depthTest!==void 0)h.depthTest=b.depthTest;if(b.vertexColors!==void 0)if(b.vertexColors=="face")h.vertexColors=THREE.FaceColors;else if(b.vertexColors)h.vertexColors=THREE.VertexColors;if(b.colorDiffuse)h.color=k(b.colorDiffuse);
else if(b.DbgColor)h.color=b.DbgColor;if(b.colorSpecular)h.specular=k(b.colorSpecular);if(b.colorAmbient)h.ambient=k(b.colorAmbient);if(b.transparency)h.opacity=b.transparency;if(b.specularCoef)h.shininess=b.specularCoef;b.mapDiffuse&&c&&g(h,"map",b.mapDiffuse,b.mapDiffuseRepeat,b.mapDiffuseOffset,b.mapDiffuseWrap);b.mapLight&&c&&g(h,"lightMap",b.mapLight,b.mapLightRepeat,b.mapLightOffset,b.mapLightWrap);b.mapNormal&&c&&g(h,"normalMap",b.mapNormal,b.mapNormalRepeat,b.mapNormalOffset,b.mapNormalWrap);
478 479
b.mapSpecular&&c&&g(h,"specularMap",b.mapSpecular,b.mapSpecularRepeat,b.mapSpecularOffset,b.mapSpecularWrap);if(b.mapNormal){var p=THREE.ShaderUtils.lib.normal,o=THREE.UniformsUtils.clone(p.uniforms),t=h.color;m=h.specular;n=h.ambient;var v=h.shininess;o.tNormal.texture=h.normalMap;if(b.mapNormalFactor)o.uNormalScale.value=b.mapNormalFactor;if(h.map)o.tDiffuse.texture=h.map,o.enableDiffuse.value=!0;if(h.specularMap)o.tSpecular.texture=h.specularMap,o.enableSpecular.value=!0;if(h.lightMap)o.tAO.texture=
h.lightMap,o.enableAO.value=!0;o.uDiffuseColor.value.setHex(t);o.uSpecularColor.value.setHex(m);o.uAmbientColor.value.setHex(n);o.uShininess.value=v;if(h.opacity)o.uOpacity.value=h.opacity;h=new THREE.MeshShaderMaterial({fragmentShader:p.fragmentShader,vertexShader:p.vertexShader,uniforms:o,lights:!0,fog:!0})}else h=new THREE[m](h);return h}};THREE.JSONLoader=function(b){THREE.Loader.call(this,b)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;
480
THREE.JSONLoader.prototype.supr=THREE.Loader.prototype;THREE.JSONLoader.prototype.load=function(b){var c=this,e=b.model,f=b.callback,g=b.texture_path?b.texture_path:this.extractUrlbase(e),b=new Worker(e);b.onmessage=function(b){c.createModel(b.data,f,g);c.onLoadComplete()};this.onLoadStart();b.postMessage((new Date).getTime())};
481 482 483 484 485
THREE.JSONLoader.prototype.createModel=function(b,c,e){var f=new THREE.Geometry,g=b.scale!==void 0?1/b.scale:1;this.init_materials(f,b.materials,e);(function(e){if(b.version===void 0||b.version!=2)console.error("Deprecated file format.");else{var c,g,n,p,o,t,v,u,w,B,A,y,G,z,C=b.faces;t=b.vertices;var H=b.normals,D=b.colors,Q=0;for(c=0;c<b.uvs.length;c++)b.uvs[c].length&&Q++;for(c=0;c<Q;c++)f.faceUvs[c]=[],f.faceVertexUvs[c]=[];p=0;for(o=t.length;p<o;)v=new THREE.Vertex,v.position.x=t[p++]*e,v.position.y=
t[p++]*e,v.position.z=t[p++]*e,f.vertices.push(v);p=0;for(o=C.length;p<o;){e=C[p++];t=e&1;n=e&2;c=e&4;g=e&8;u=e&16;v=e&32;B=e&64;e&=128;t?(A=new THREE.Face4,A.a=C[p++],A.b=C[p++],A.c=C[p++],A.d=C[p++],t=4):(A=new THREE.Face3,A.a=C[p++],A.b=C[p++],A.c=C[p++],t=3);if(n)n=C[p++],A.materials=f.materials[n];n=f.faces.length;if(c)for(c=0;c<Q;c++)y=b.uvs[c],w=C[p++],z=y[w*2],w=y[w*2+1],f.faceUvs[c][n]=new THREE.UV(z,w);if(g)for(c=0;c<Q;c++){y=b.uvs[c];G=[];for(g=0;g<t;g++)w=C[p++],z=y[w*2],w=y[w*2+1],G[g]=
new THREE.UV(z,w);f.faceVertexUvs[c][n]=G}if(u)u=C[p++]*3,g=new THREE.Vector3,g.x=H[u++],g.y=H[u++],g.z=H[u],A.normal=g;if(v)for(c=0;c<t;c++)u=C[p++]*3,g=new THREE.Vector3,g.x=H[u++],g.y=H[u++],g.z=H[u],A.vertexNormals.push(g);if(B)v=C[p++],v=new THREE.Color(D[v]),A.color=v;if(e)for(c=0;c<t;c++)v=C[p++],v=new THREE.Color(D[v]),A.vertexColors.push(v);f.faces.push(A)}}})(g);(function(){var c,e,g,n;if(b.skinWeights){c=0;for(e=b.skinWeights.length;c<e;c+=2)g=b.skinWeights[c],n=b.skinWeights[c+1],f.skinWeights.push(new THREE.Vector4(g,
n,0,0))}if(b.skinIndices){c=0;for(e=b.skinIndices.length;c<e;c+=2)g=b.skinIndices[c],n=b.skinIndices[c+1],f.skinIndices.push(new THREE.Vector4(g,n,0,0))}f.bones=b.bones;f.animation=b.animation})();(function(c){if(b.morphTargets!==void 0){var e,g,n,p,o,t,v,u,w;e=0;for(g=b.morphTargets.length;e<g;e++){f.morphTargets[e]={};f.morphTargets[e].name=b.morphTargets[e].name;f.morphTargets[e].vertices=[];u=f.morphTargets[e].vertices;w=b.morphTargets[e].vertices;n=0;for(p=w.length;n<p;n+=3)o=w[n]*c,t=w[n+1]*
c,v=w[n+2]*c,u.push(new THREE.Vertex(new THREE.Vector3(o,t,v)))}}if(b.morphColors!==void 0){e=0;for(g=b.morphColors.length;e<g;e++){f.morphColors[e]={};f.morphColors[e].name=b.morphColors[e].name;f.morphColors[e].colors=[];p=f.morphColors[e].colors;o=b.morphColors[e].colors;c=0;for(n=o.length;c<n;c+=3)t=new THREE.Color(16755200),t.setRGB(o[c],o[c+1],o[c+2]),p.push(t)}}})(g);(function(){if(b.edges!==void 0){var c,e,g;for(c=0;c<b.edges.length;c+=2)e=b.edges[c],g=b.edges[c+1],f.edges.push(new THREE.Edge(f.vertices[e],
M
Mr.doob 已提交
486
f.vertices[g],e,g))}})();f.computeCentroids();f.computeFaceNormals();this.hasNormals(f)&&f.computeTangents();c(f)};THREE.BinaryLoader=function(b){THREE.Loader.call(this,b)};THREE.BinaryLoader.prototype=new THREE.Loader;THREE.BinaryLoader.prototype.constructor=THREE.BinaryLoader;THREE.BinaryLoader.prototype.supr=THREE.Loader.prototype;
M
Mr.doob 已提交
487
THREE.BinaryLoader.prototype={load:function(b){var c=b.model,e=b.callback,f=b.texture_path?b.texture_path:THREE.Loader.prototype.extractUrlbase(c),g=b.bin_path?b.bin_path:THREE.Loader.prototype.extractUrlbase(c),b=(new Date).getTime(),c=new Worker(c),k=this.showProgress?THREE.Loader.prototype.updateProgress:null;c.onmessage=function(b){THREE.BinaryLoader.prototype.loadAjaxBuffers(b.data.buffers,b.data.materials,e,g,f,k)};c.onerror=function(b){alert("worker.onerror: "+b.message+"\n"+b.data);b.preventDefault()};
M
Mr.doob 已提交
488
c.postMessage(b)},loadAjaxBuffers:function(b,c,e,f,g,k){var h=new XMLHttpRequest,m=f+"/"+b,n=0;h.onreadystatechange=function(){h.readyState==4?h.status==200||h.status==0?THREE.BinaryLoader.prototype.createBinModel(h.responseText,e,g,c):alert("Couldn't load ["+m+"] ["+h.status+"]"):h.readyState==3?k&&(n==0&&(n=h.getResponseHeader("Content-Length")),k({total:n,loaded:h.responseText.length})):h.readyState==2&&(n=h.getResponseHeader("Content-Length"))};h.open("GET",m,!0);h.overrideMimeType("text/plain; charset=x-user-defined");
489
h.setRequestHeader("Content-Type","text/plain");h.send(null)},createBinModel:function(b,c,e,f){var g=function(c){function e(b,c){var f=o(b,c),g=o(b,c+1),h=o(b,c+2),j=o(b,c+3),k=(j<<1&255|h>>7)-127;f|=(h&127)<<16|g<<8;if(f==0&&k==-127)return 0;return(1-2*(j>>7))*(1+f*Math.pow(2,-23))*Math.pow(2,k)}function g(b,c){var e=o(b,c),f=o(b,c+1),h=o(b,c+2);return(o(b,c+3)<<24)+(h<<16)+(f<<8)+e}function n(b,c){var e=o(b,c);return(o(b,c+1)<<8)+e}function p(b,c){var e=o(b,c);return e>127?e-256:e}function o(b,
M
Mr.doob 已提交
490 491
c){return b.charCodeAt(c)&255}function t(c){var e,f,h;e=g(b,c);f=g(b,c+D);h=g(b,c+Q);c=n(b,c+J);THREE.BinaryLoader.prototype.f3(y,e,f,h,c)}function v(c){var e,f,h,j,k,o;e=g(b,c);f=g(b,c+D);h=g(b,c+Q);j=n(b,c+J);k=g(b,c+F);o=g(b,c+I);c=g(b,c+S);THREE.BinaryLoader.prototype.f3n(y,C,e,f,h,j,k,o,c)}function u(c){var e,f,h,k;e=g(b,c);f=g(b,c+K);h=g(b,c+ea);k=g(b,c+j);c=n(b,c+ca);THREE.BinaryLoader.prototype.f4(y,e,f,h,k,c)}function w(c){var e,f,h,k,o,p,t,u;e=g(b,c);f=g(b,c+K);h=g(b,c+ea);k=g(b,c+j);o=
n(b,c+ca);p=g(b,c+T);t=g(b,c+Z);u=g(b,c+N);c=g(b,c+da);THREE.BinaryLoader.prototype.f4n(y,C,e,f,h,k,o,p,t,u,c)}function B(c){var e,f;e=g(b,c);f=g(b,c+X);c=g(b,c+aa);THREE.BinaryLoader.prototype.uv3(y.faceVertexUvs[0],H[e*2],H[e*2+1],H[f*2],H[f*2+1],H[c*2],H[c*2+1])}function A(c){var e,f,h;e=g(b,c);f=g(b,c+ia);h=g(b,c+ha);c=g(b,c+na);THREE.BinaryLoader.prototype.uv4(y.faceVertexUvs[0],H[e*2],H[e*2+1],H[f*2],H[f*2+1],H[h*2],H[h*2+1],H[c*2],H[c*2+1])}var y=this,G=0,z,C=[],H=[],D,Q,J,F,I,S,K,ea,j,ca,
492
T,Z,N,da,X,aa,ia,ha,na,ja,L,fa,V,U,$;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(y,f,c);z={signature:b.substr(G,8),header_bytes:o(b,G+8),vertex_coordinate_bytes:o(b,G+9),normal_coordinate_bytes:o(b,G+10),uv_coordinate_bytes:o(b,G+11),vertex_index_bytes:o(b,G+12),normal_index_bytes:o(b,G+13),uv_index_bytes:o(b,G+14),material_index_bytes:o(b,G+15),nvertices:g(b,G+16),nnormals:g(b,G+16+4),nuvs:g(b,G+16+8),ntri_flat:g(b,G+16+12),ntri_smooth:g(b,G+16+16),ntri_flat_uv:g(b,G+16+20),ntri_smooth_uv:g(b,
M
Mr.doob 已提交
493
G+16+24),nquad_flat:g(b,G+16+28),nquad_smooth:g(b,G+16+32),nquad_flat_uv:g(b,G+16+36),nquad_smooth_uv:g(b,G+16+40)};G+=z.header_bytes;D=z.vertex_index_bytes;Q=z.vertex_index_bytes*2;J=z.vertex_index_bytes*3;F=z.vertex_index_bytes*3+z.material_index_bytes;I=z.vertex_index_bytes*3+z.material_index_bytes+z.normal_index_bytes;S=z.vertex_index_bytes*3+z.material_index_bytes+z.normal_index_bytes*2;K=z.vertex_index_bytes;ea=z.vertex_index_bytes*2;j=z.vertex_index_bytes*3;ca=z.vertex_index_bytes*4;T=z.vertex_index_bytes*
M
Mr.doob 已提交
494
4+z.material_index_bytes;Z=z.vertex_index_bytes*4+z.material_index_bytes+z.normal_index_bytes;N=z.vertex_index_bytes*4+z.material_index_bytes+z.normal_index_bytes*2;da=z.vertex_index_bytes*4+z.material_index_bytes+z.normal_index_bytes*3;X=z.uv_index_bytes;aa=z.uv_index_bytes*2;ia=z.uv_index_bytes;ha=z.uv_index_bytes*2;na=z.uv_index_bytes*3;c=z.vertex_index_bytes*3+z.material_index_bytes;$=z.vertex_index_bytes*4+z.material_index_bytes;ja=z.ntri_flat*c;L=z.ntri_smooth*(c+z.normal_index_bytes*3);fa=
495 496
z.ntri_flat_uv*(c+z.uv_index_bytes*3);V=z.ntri_smooth_uv*(c+z.normal_index_bytes*3+z.uv_index_bytes*3);U=z.nquad_flat*$;c=z.nquad_smooth*($+z.normal_index_bytes*4);$=z.nquad_flat_uv*($+z.uv_index_bytes*4);G+=function(c){for(var f,g,j,k=z.vertex_coordinate_bytes*3,m=c+z.nvertices*k;c<m;c+=k)f=e(b,c),g=e(b,c+z.vertex_coordinate_bytes),j=e(b,c+z.vertex_coordinate_bytes*2),THREE.BinaryLoader.prototype.v(y,f,g,j);return z.nvertices*k}(G);G+=function(c){for(var e,f,g,h=z.normal_coordinate_bytes*3,j=c+z.nnormals*
h;c<j;c+=h)e=p(b,c),f=p(b,c+z.normal_coordinate_bytes),g=p(b,c+z.normal_coordinate_bytes*2),C.push(e/127,f/127,g/127);return z.nnormals*h}(G);G+=function(c){for(var f,g,j=z.uv_coordinate_bytes*2,k=c+z.nuvs*j;c<k;c+=j)f=e(b,c),g=e(b,c+z.uv_coordinate_bytes),H.push(f,g);return z.nuvs*j}(G);ja=G+ja;L=ja+L;fa=L+fa;V=fa+V;U=V+U;c=U+c;$=c+$;(function(b){var c,e=z.vertex_index_bytes*3+z.material_index_bytes,f=e+z.uv_index_bytes*3,g=b+z.ntri_flat_uv*f;for(c=b;c<g;c+=f)t(c),B(c+e);return g-b})(L);(function(b){var c,
M
Mr.doob 已提交
497
e=z.vertex_index_bytes*3+z.material_index_bytes+z.normal_index_bytes*3,f=e+z.uv_index_bytes*3,g=b+z.ntri_smooth_uv*f;for(c=b;c<g;c+=f)v(c),B(c+e);return g-b})(fa);(function(b){var c,e=z.vertex_index_bytes*4+z.material_index_bytes,f=e+z.uv_index_bytes*4,g=b+z.nquad_flat_uv*f;for(c=b;c<g;c+=f)u(c),A(c+e);return g-b})(c);(function(b){var c,e=z.vertex_index_bytes*4+z.material_index_bytes+z.normal_index_bytes*4,f=e+z.uv_index_bytes*4,g=b+z.nquad_smooth_uv*f;for(c=b;c<g;c+=f)w(c),A(c+e);return g-b})($);
498
(function(b){var c,e=z.vertex_index_bytes*3+z.material_index_bytes,f=b+z.ntri_flat*e;for(c=b;c<f;c+=e)t(c);return f-b})(G);(function(b){var c,e=z.vertex_index_bytes*3+z.material_index_bytes+z.normal_index_bytes*3,f=b+z.ntri_smooth*e;for(c=b;c<f;c+=e)v(c);return f-b})(ja);(function(b){var c,e=z.vertex_index_bytes*4+z.material_index_bytes,f=b+z.nquad_flat*e;for(c=b;c<f;c+=e)u(c);return f-b})(V);(function(b){var c,e=z.vertex_index_bytes*4+z.material_index_bytes+z.normal_index_bytes*4,f=b+z.nquad_smooth*
M
Mr.doob 已提交
499
e;for(c=b;c<f;c+=e)w(c);return f-b})(U);this.computeCentroids();this.computeFaceNormals();THREE.Loader.prototype.hasNormals(this)&&this.computeTangents()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;c(new g(e))},v:function(b,c,e,f){b.vertices.push(new THREE.Vertex(new THREE.Vector3(c,e,f)))},f3:function(b,c,e,f,g){b.faces.push(new THREE.Face3(c,e,f,null,null,b.materials[g]))},f4:function(b,c,e,f,g,k){b.faces.push(new THREE.Face4(c,e,f,g,null,null,b.materials[k]))},f3n:function(b,c,e,
500 501
f,g,k,h,m,n){var k=b.materials[k],p=c[m*3],o=c[m*3+1],m=c[m*3+2],t=c[n*3],v=c[n*3+1],n=c[n*3+2];b.faces.push(new THREE.Face3(e,f,g,[new THREE.Vector3(c[h*3],c[h*3+1],c[h*3+2]),new THREE.Vector3(p,o,m),new THREE.Vector3(t,v,n)],null,k))},f4n:function(b,c,e,f,g,k,h,m,n,p,o){var h=b.materials[h],t=c[n*3],v=c[n*3+1],n=c[n*3+2],u=c[p*3],w=c[p*3+1],p=c[p*3+2],B=c[o*3],A=c[o*3+1],o=c[o*3+2];b.faces.push(new THREE.Face4(e,f,g,k,[new THREE.Vector3(c[m*3],c[m*3+1],c[m*3+2]),new THREE.Vector3(t,v,n),new THREE.Vector3(u,
w,p),new THREE.Vector3(B,A,o)],null,h))},uv3:function(b,c,e,f,g,k,h){var m=[];m.push(new THREE.UV(c,e));m.push(new THREE.UV(f,g));m.push(new THREE.UV(k,h));b.push(m)},uv4:function(b,c,e,f,g,k,h,m,n){var p=[];p.push(new THREE.UV(c,e));p.push(new THREE.UV(f,g));p.push(new THREE.UV(k,h));p.push(new THREE.UV(m,n));b.push(p)}};
M
Mr.doob 已提交
502
THREE.SceneLoader=function(){this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){};this.callbackSync=function(){};this.callbackProgress=function(){}};
M
Mr.doob 已提交
503
THREE.SceneLoader.prototype={load:function(b,c){var e=this,f=new Worker(b);f.postMessage(0);var g=THREE.Loader.prototype.extractUrlbase(b);f.onmessage=function(b){function f(b,c){return c=="relativeToHTML"?b:g+"/"+b}function m(){for(u in K.objects)if(!N.objects[u])if(G=K.objects[u],G.geometry!==void 0){if(D=N.geometries[G.geometry]){var b=!1;I=[];for(X=0;X<G.materials.length;X++)I[X]=N.materials[G.materials[X]],b=I[X]instanceof THREE.MeshShaderMaterial;b&&D.computeTangents();z=G.position;r=G.rotation;
M
Mr.doob 已提交
504 505
q=G.quaternion;s=G.scale;q=0;I.length==0&&(I[0]=new THREE.MeshFaceMaterial);I.length>1&&(I=[new THREE.MeshFaceMaterial]);object=new THREE.Mesh(D,I);object.name=u;object.position.set(z[0],z[1],z[2]);q?(object.quaternion.set(q[0],q[1],q[2],q[3]),object.useQuaternion=!0):object.rotation.set(r[0],r[1],r[2]);object.scale.set(s[0],s[1],s[2]);object.visible=G.visible;N.scene.addObject(object);N.objects[u]=object;G.meshCollider&&(b=THREE.CollisionUtils.MeshColliderWBox(object),N.scene.collisions.colliders.push(b));
if(G.castsShadow)b=new THREE.ShadowVolume(D),N.scene.addChild(b),b.position=object.position,b.rotation=object.rotation,b.scale=object.scale;G.trigger&&G.trigger.toLowerCase()!="none"&&(b={type:G.trigger,object:G},N.triggers[object.name]=b)}}else z=G.position,r=G.rotation,q=G.quaternion,s=G.scale,q=0,object=new THREE.Object3D,object.name=u,object.position.set(z[0],z[1],z[2]),q?(object.quaternion.set(q[0],q[1],q[2],q[3]),object.useQuaternion=!0):object.rotation.set(r[0],r[1],r[2]),object.scale.set(s[0],
506
s[1],s[2]),object.visible=G.visible!==void 0?G.visible:!1,N.scene.addObject(object),N.objects[u]=object,N.empties[u]=object,G.trigger&&G.trigger.toLowerCase()!="none"&&(b={type:G.trigger,object:G},N.triggers[object.name]=b)}function n(b){return function(c){N.geometries[b]=c;m();j-=1;e.onLoadComplete();o()}}function p(b){return function(c){N.geometries[b]=c}}function o(){e.callbackProgress({totalModels:T,totalTextures:Z,loadedModels:T-j,loadedTextures:Z-ca},N);e.onLoadProgress();j==0&&ca==0&&c(N)}
M
Mr.doob 已提交
507
var t,v,u,w,B,A,y,G,z,C,H,D,Q,J,F,I,S,K,ea,j,ca,T,Z,N;K=b.data;F=new THREE.BinaryLoader;ea=new THREE.JSONLoader;ca=j=0;N={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},triggers:{},empties:{}};b=!1;for(u in K.objects)if(G=K.objects[u],G.meshCollider){b=!0;break}if(b)N.scene.collisions=new THREE.CollisionSystem;if(K.transform){b=K.transform.position;C=K.transform.rotation;var da=K.transform.scale;b&&N.scene.position.set(b[0],b[1],b[2]);C&&N.scene.rotation.set(C[0],
508
C[1],C[2]);da&&N.scene.scale.set(da[0],da[1],da[2]);(b||C||da)&&N.scene.updateMatrix()}b=function(){ca-=1;o();e.onLoadComplete()};for(B in K.cameras){C=K.cameras[B];if(C.type=="perspective")Q=new THREE.Camera(C.fov,C.aspect,C.near,C.far);else if(C.type=="ortho")Q=new THREE.Camera,Q.projectionMatrix=THREE.Matrix4.makeOrtho(C.left,C.right,C.top,C.bottom,C.near,C.far);z=C.position;C=C.target;Q.position.set(z[0],z[1],z[2]);Q.target.position.set(C[0],C[1],C[2]);N.cameras[B]=Q}for(w in K.lights)B=K.lights[w],
M
Mr.doob 已提交
509 510 511
Q=B.color!==void 0?B.color:16777215,C=B.intensity!==void 0?B.intensity:1,B.type=="directional"?(z=B.direction,S=new THREE.DirectionalLight(Q,C),S.position.set(z[0],z[1],z[2]),S.position.normalize()):B.type=="point"?(z=B.position,d=B.distance,S=new THREE.PointLight(Q,C,d),S.position.set(z[0],z[1],z[2])):B.type=="ambient"&&(S=new THREE.AmbientLight(Q)),N.scene.addLight(S),N.lights[w]=S;for(A in K.fogs)w=K.fogs[A],w.type=="linear"?J=new THREE.Fog(0,w.near,w.far):w.type=="exp2"&&(J=new THREE.FogExp2(0,
w.density)),C=w.color,J.color.setRGB(C[0],C[1],C[2]),N.fogs[A]=J;if(N.cameras&&K.defaults.camera)N.currentCamera=N.cameras[K.defaults.camera];if(N.fogs&&K.defaults.fog)N.scene.fog=N.fogs[K.defaults.fog];C=K.defaults.bgcolor;N.bgColor=new THREE.Color;N.bgColor.setRGB(C[0],C[1],C[2]);N.bgColorAlpha=K.defaults.bgalpha;for(t in K.geometries)if(A=K.geometries[t],A.type=="bin_mesh"||A.type=="ascii_mesh")j+=1,e.onLoadStart();T=j;for(t in K.geometries)A=K.geometries[t],A.type=="cube"?(D=new THREE.CubeGeometry(A.width,
A.height,A.depth,A.segmentsWidth,A.segmentsHeight,A.segmentsDepth,null,A.flipped,A.sides),N.geometries[t]=D):A.type=="plane"?(D=new THREE.PlaneGeometry(A.width,A.height,A.segmentsWidth,A.segmentsHeight),N.geometries[t]=D):A.type=="sphere"?(D=new THREE.SphereGeometry(A.radius,A.segmentsWidth,A.segmentsHeight),N.geometries[t]=D):A.type=="cylinder"?(D=new THREE.CylinderGeometry(A.numSegs,A.topRad,A.botRad,A.height,A.topOffset,A.botOffset),N.geometries[t]=D):A.type=="torus"?(D=new THREE.TorusGeometry(A.radius,
512
A.tube,A.segmentsR,A.segmentsT),N.geometries[t]=D):A.type=="icosahedron"?(D=new THREE.IcosahedronGeometry(A.subdivisions),N.geometries[t]=D):A.type=="bin_mesh"?F.load({model:f(A.url,K.urlBaseType),callback:n(t)}):A.type=="ascii_mesh"?ea.load({model:f(A.url,K.urlBaseType),callback:n(t)}):A.type=="embedded_mesh"&&(A=K.embeds[A.id])&&ea.createModel(A,p(t),"");for(y in K.textures)if(t=K.textures[y],t.url instanceof Array){ca+=t.url.length;for(F=0;F<t.url.length;F++)e.onLoadStart()}else ca+=1,e.onLoadStart();
M
Mr.doob 已提交
513 514 515
Z=ca;for(y in K.textures){t=K.textures[y];if(t.mapping!=void 0&&THREE[t.mapping]!=void 0)t.mapping=new THREE[t.mapping];if(t.url instanceof Array){F=[];for(var X=0;X<t.url.length;X++)F[X]=f(t.url[X],K.urlBaseType);F=THREE.ImageUtils.loadTextureCube(F,t.mapping,b)}else{F=THREE.ImageUtils.loadTexture(f(t.url,K.urlBaseType),t.mapping,b);if(THREE[t.minFilter]!=void 0)F.minFilter=THREE[t.minFilter];if(THREE[t.magFilter]!=void 0)F.magFilter=THREE[t.magFilter];if(t.repeat){F.repeat.set(t.repeat[0],t.repeat[1]);
if(t.repeat[0]!=1)F.wrapS=THREE.RepeatWrapping;if(t.repeat[1]!=1)F.wrapT=THREE.RepeatWrapping}t.offset&&F.offset.set(t.offset[0],t.offset[1]);if(t.wrap){ea={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(ea[t.wrap[0]]!==void 0)F.wrapS=ea[t.wrap[0]];if(ea[t.wrap[1]]!==void 0)F.wrapT=ea[t.wrap[1]]}}N.textures[y]=F}for(v in K.materials){y=K.materials[v];for(H in y.parameters)if(H=="envMap"||H=="map"||H=="lightMap")y.parameters[H]=N.textures[y.parameters[H]];else if(H=="shading")y.parameters[H]=
y.parameters[H]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(H=="blending")y.parameters[H]=THREE[y.parameters[H]]?THREE[y.parameters[H]]:THREE.NormalBlending;else if(H=="combine")y.parameters[H]=y.parameters[H]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(H=="vertexColors")if(y.parameters[H]=="face")y.parameters[H]=THREE.FaceColors;else if(y.parameters[H])y.parameters[H]=THREE.VertexColors;if(y.parameters.opacity!==void 0&&y.parameters.opacity<1)y.parameters.transparent=
516
!0;if(y.parameters.normalMap){t=THREE.ShaderUtils.lib.normal;b=THREE.UniformsUtils.clone(t.uniforms);F=y.parameters.color;ea=y.parameters.specular;A=y.parameters.ambient;J=y.parameters.shininess;b.tNormal.texture=N.textures[y.parameters.normalMap];if(y.parameters.normalMapFactor)b.uNormalScale.value=y.parameters.normalMapFactor;if(y.parameters.map)b.tDiffuse.texture=y.parameters.map,b.enableDiffuse.value=!0;if(y.parameters.lightMap)b.tAO.texture=y.parameters.lightMap,b.enableAO.value=!0;if(y.parameters.specularMap)b.tSpecular.texture=
A
alteredq 已提交
517
N.textures[y.parameters.specularMap],b.enableSpecular.value=!0;b.uDiffuseColor.value.setHex(F);b.uSpecularColor.value.setHex(ea);b.uAmbientColor.value.setHex(A);b.uShininess.value=J;if(y.parameters.opacity)b.uOpacity.value=y.parameters.opacity;y=new THREE.MeshShaderMaterial({fragmentShader:t.fragmentShader,vertexShader:t.vertexShader,uniforms:b,lights:!0,fog:!0})}else y=new THREE[y.type](y.parameters);N.materials[v]=y}m();e.callbackSync(N)}}};
518
THREE.MarchingCubes=function(b,c){THREE.Object3D.call(this);this.materials=c instanceof Array?c:[c];this.init=function(b){this.isolation=80;this.size=b;this.size2=this.size*this.size;this.size3=this.size2*this.size;this.halfsize=this.size/2;this.delta=2/this.size;this.yd=this.size;this.zd=this.size2;this.field=new Float32Array(this.size3);this.normal_cache=new Float32Array(this.size3*3);this.vlist=new Float32Array(36);this.nlist=new Float32Array(36);this.firstDraw=!0;this.maxCount=4096;this.count=
519 520 521 522 523 524
0;this.hasNormal=this.hasPos=!1;this.positionArray=new Float32Array(this.maxCount*3);this.normalArray=new Float32Array(this.maxCount*3)};this.lerp=function(b,c,g){return b+(c-b)*g};this.VIntX=function(b,c,g,k,h,m,n,p,o,t){h=(h-o)/(t-o);o=this.normal_cache;c[k]=m+h*this.delta;c[k+1]=n;c[k+2]=p;g[k]=this.lerp(o[b],o[b+3],h);g[k+1]=this.lerp(o[b+1],o[b+4],h);g[k+2]=this.lerp(o[b+2],o[b+5],h)};this.VIntY=function(b,c,g,k,h,m,n,p,o,t){h=(h-o)/(t-o);o=this.normal_cache;c[k]=m;c[k+1]=n+h*this.delta;c[k+
2]=p;c=b+this.yd*3;g[k]=this.lerp(o[b],o[c],h);g[k+1]=this.lerp(o[b+1],o[c+1],h);g[k+2]=this.lerp(o[b+2],o[c+2],h)};this.VIntZ=function(b,c,g,k,h,m,n,p,o,t){h=(h-o)/(t-o);o=this.normal_cache;c[k]=m;c[k+1]=n;c[k+2]=p+h*this.delta;c=b+this.zd*3;g[k]=this.lerp(o[b],o[c],h);g[k+1]=this.lerp(o[b+1],o[c+1],h);g[k+2]=this.lerp(o[b+2],o[c+2],h)};this.compNorm=function(b){var c=b*3;this.normal_cache[c]==0&&(this.normal_cache[c]=this.field[b-1]-this.field[b+1],this.normal_cache[c+1]=this.field[b-this.yd]-this.field[b+
this.yd],this.normal_cache[c+2]=this.field[b-this.zd]-this.field[b+this.zd])};this.polygonize=function(b,c,g,k,h,m){var n=k+1,p=k+this.yd,o=k+this.zd,t=n+this.yd,v=n+this.zd,u=k+this.yd+this.zd,w=n+this.yd+this.zd,B=0,A=this.field[k],y=this.field[n],G=this.field[p],z=this.field[t],C=this.field[o],H=this.field[v],D=this.field[u],Q=this.field[w];A<h&&(B|=1);y<h&&(B|=2);G<h&&(B|=8);z<h&&(B|=4);C<h&&(B|=16);H<h&&(B|=32);D<h&&(B|=128);Q<h&&(B|=64);var J=THREE.edgeTable[B];if(J==0)return 0;var F=this.delta,
I=b+F,S=c+F,F=g+F;J&1&&(this.compNorm(k),this.compNorm(n),this.VIntX(k*3,this.vlist,this.nlist,0,h,b,c,g,A,y));J&2&&(this.compNorm(n),this.compNorm(t),this.VIntY(n*3,this.vlist,this.nlist,3,h,I,c,g,y,z));J&4&&(this.compNorm(p),this.compNorm(t),this.VIntX(p*3,this.vlist,this.nlist,6,h,b,S,g,G,z));J&8&&(this.compNorm(k),this.compNorm(p),this.VIntY(k*3,this.vlist,this.nlist,9,h,b,c,g,A,G));J&16&&(this.compNorm(o),this.compNorm(v),this.VIntX(o*3,this.vlist,this.nlist,12,h,b,c,F,C,H));J&32&&(this.compNorm(v),
this.compNorm(w),this.VIntY(v*3,this.vlist,this.nlist,15,h,I,c,F,H,Q));J&64&&(this.compNorm(u),this.compNorm(w),this.VIntX(u*3,this.vlist,this.nlist,18,h,b,S,F,D,Q));J&128&&(this.compNorm(o),this.compNorm(u),this.VIntY(o*3,this.vlist,this.nlist,21,h,b,c,F,C,D));J&256&&(this.compNorm(k),this.compNorm(o),this.VIntZ(k*3,this.vlist,this.nlist,24,h,b,c,g,A,C));J&512&&(this.compNorm(n),this.compNorm(v),this.VIntZ(n*3,this.vlist,this.nlist,27,h,I,c,g,y,H));J&1024&&(this.compNorm(t),this.compNorm(w),this.VIntZ(t*
3,this.vlist,this.nlist,30,h,I,S,g,z,Q));J&2048&&(this.compNorm(p),this.compNorm(u),this.VIntZ(p*3,this.vlist,this.nlist,33,h,b,S,g,G,D));B<<=4;for(h=k=0;THREE.triTable[B+h]!=-1;)b=B+h,c=b+1,g=b+2,this.posnormtriv(this.vlist,this.nlist,3*THREE.triTable[b],3*THREE.triTable[c],3*THREE.triTable[g],m),h+=3,k++;return k};this.posnormtriv=function(b,c,g,k,h,m){var n=this.count*3;this.positionArray[n]=b[g];this.positionArray[n+1]=b[g+1];this.positionArray[n+2]=b[g+2];this.positionArray[n+3]=b[k];this.positionArray[n+
M
Mr.doob 已提交
525
4]=b[k+1];this.positionArray[n+5]=b[k+2];this.positionArray[n+6]=b[h];this.positionArray[n+7]=b[h+1];this.positionArray[n+8]=b[h+2];this.normalArray[n]=c[g];this.normalArray[n+1]=c[g+1];this.normalArray[n+2]=c[g+2];this.normalArray[n+3]=c[k];this.normalArray[n+4]=c[k+1];this.normalArray[n+5]=c[k+2];this.normalArray[n+6]=c[h];this.normalArray[n+7]=c[h+1];this.normalArray[n+8]=c[h+2];this.hasNormal=this.hasPos=!0;this.count+=3;this.count>=this.maxCount-3&&m(this)};this.begin=function(){this.count=0;
526 527 528 529 530
this.hasNormal=this.hasPos=!1};this.end=function(b){if(this.count!=0){for(var c=this.count*3;c<this.positionArray.length;c++)this.positionArray[c]=0;b(this)}};this.addBall=function(b,c,g,k,h){var m=this.size*Math.sqrt(k/h),n=g*this.size,p=c*this.size,o=b*this.size,t=Math.floor(n-m);t<1&&(t=1);n=Math.floor(n+m);n>this.size-1&&(n=this.size-1);var v=Math.floor(p-m);v<1&&(v=1);p=Math.floor(p+m);p>this.size-1&&(p=this.size-1);var u=Math.floor(o-m);u<1&&(u=1);m=Math.floor(o+m);m>this.size-1&&(m=this.size-
1);for(var w,B,A,y,G,z;t<n;t++){o=this.size2*t;B=t/this.size-g;G=B*B;for(B=v;B<p;B++){A=o+this.size*B;w=B/this.size-c;z=w*w;for(w=u;w<m;w++)y=w/this.size-b,y=k/(1.0E-6+y*y+z+G)-h,y>0&&(this.field[A+w]+=y)}}};this.addPlaneX=function(b,c){var g,k,h,m,n,p=this.size,o=this.yd,t=this.zd,v=this.field,u=p*Math.sqrt(b/c);u>p&&(u=p);for(g=0;g<u;g++)if(k=g/p,k*=k,m=b/(1.0E-4+k)-c,m>0)for(k=0;k<p;k++){n=g+k*o;for(h=0;h<p;h++)v[t*h+n]+=m}};this.addPlaneY=function(b,c){var g,k,h,m,n,p,o=this.size,t=this.yd,v=
this.zd,u=this.field,w=o*Math.sqrt(b/c);w>o&&(w=o);for(k=0;k<w;k++)if(g=k/o,g*=g,m=b/(1.0E-4+g)-c,m>0){n=k*t;for(g=0;g<o;g++){p=n+g;for(h=0;h<o;h++)u[v*h+p]+=m}}};this.addPlaneZ=function(b,c){var g,k,h,m,n,p;size=this.size;yd=this.yd;zd=this.zd;field=this.field;dist=size*Math.sqrt(b/c);dist>size&&(dist=size);for(h=0;h<dist;h++)if(g=h/size,g*=g,m=b/(1.0E-4+g)-c,m>0){n=zd*h;for(k=0;k<size;k++){p=n+k*yd;for(g=0;g<size;g++)field[p+g]+=m}}};this.reset=function(){var b;for(b=0;b<this.size3;b++)this.normal_cache[b*
3]=0,this.field[b]=0};this.render=function(b){this.begin();var c,g,k,h,m,n,p,o,t,v=this.size-2;for(h=1;h<v;h++){t=this.size2*h;p=(h-this.halfsize)/this.halfsize;for(k=1;k<v;k++){o=t+this.size*k;n=(k-this.halfsize)/this.halfsize;for(g=1;g<v;g++)m=(g-this.halfsize)/this.halfsize,c=o+g,this.polygonize(m,n,p,c,this.isolation,b)}}this.end(b)};this.generateGeometry=function(){var b=0,c=new THREE.Geometry,g=[];this.render(function(k){var h,m,n,p,o,t,v,u;for(h=0;h<k.count;h++)v=h*3,o=v+1,u=v+2,m=k.positionArray[v],
n=k.positionArray[o],p=k.positionArray[u],t=new THREE.Vector3(m,n,p),m=k.normalArray[v],n=k.normalArray[o],p=k.normalArray[u],v=new THREE.Vector3(m,n,p),v.normalize(),o=new THREE.Vertex(t),c.vertices.push(o),g.push(v);nfaces=k.count/3;for(h=0;h<nfaces;h++)v=(b+h)*3,o=v+1,u=v+2,t=g[v],m=g[o],n=g[u],v=new THREE.Face3(v,o,u,[t,m,n]),c.faces.push(v);b+=nfaces;k.count=0});return c};this.init(b)};THREE.MarchingCubes.prototype=new THREE.Object3D;THREE.MarchingCubes.prototype.constructor=THREE.MarchingCubes;
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
THREE.edgeTable=new Int32Array([0,265,515,778,1030,1295,1541,1804,2060,2309,2575,2822,3082,3331,3593,3840,400,153,915,666,1430,1183,1941,1692,2460,2197,2975,2710,3482,3219,3993,3728,560,825,51,314,1590,1855,1077,1340,2620,2869,2111,2358,3642,3891,3129,3376,928,681,419,170,1958,1711,1445,1196,2988,2725,2479,2214,4010,3747,3497,3232,1120,1385,1635,1898,102,367,613,876,3180,3429,3695,3942,2154,2403,2665,2912,1520,1273,2035,1786,502,255,1013,764,3580,3317,4095,3830,2554,2291,3065,2800,1616,1881,1107,
1370,598,863,85,348,3676,3925,3167,3414,2650,2899,2137,2384,1984,1737,1475,1226,966,719,453,204,4044,3781,3535,3270,3018,2755,2505,2240,2240,2505,2755,3018,3270,3535,3781,4044,204,453,719,966,1226,1475,1737,1984,2384,2137,2899,2650,3414,3167,3925,3676,348,85,863,598,1370,1107,1881,1616,2800,3065,2291,2554,3830,4095,3317,3580,764,1013,255,502,1786,2035,1273,1520,2912,2665,2403,2154,3942,3695,3429,3180,876,613,367,102,1898,1635,1385,1120,3232,3497,3747,4010,2214,2479,2725,2988,1196,1445,1711,1958,170,
419,681,928,3376,3129,3891,3642,2358,2111,2869,2620,1340,1077,1855,1590,314,51,825,560,3728,3993,3219,3482,2710,2975,2197,2460,1692,1941,1183,1430,666,915,153,400,3840,3593,3331,3082,2822,2575,2309,2060,1804,1541,1295,1030,778,515,265,0]);
THREE.triTable=new Int32Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,9,8,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,2,10,0,2,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,8,3,2,10,8,10,9,8,-1,-1,-1,-1,-1,-1,-1,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,8,11,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,11,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,1,11,2,1,9,11,9,8,11,-1,-1,-1,-1,-1,-1,-1,3,10,1,11,10,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,10,1,0,8,10,8,11,10,-1,-1,-1,-1,-1,-1,-1,3,9,0,3,11,9,11,10,9,-1,-1,-1,-1,-1,-1,-1,9,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,7,3,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,1,9,4,7,1,7,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,4,7,3,0,4,1,2,10,-1,-1,-1,-1,-1,-1,-1,9,2,10,9,0,2,8,4,7,
-1,-1,-1,-1,-1,-1,-1,2,10,9,2,9,7,2,7,3,7,9,4,-1,-1,-1,-1,8,4,7,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,4,7,11,2,4,2,0,4,-1,-1,-1,-1,-1,-1,-1,9,0,1,8,4,7,2,3,11,-1,-1,-1,-1,-1,-1,-1,4,7,11,9,4,11,9,11,2,9,2,1,-1,-1,-1,-1,3,10,1,3,11,10,7,8,4,-1,-1,-1,-1,-1,-1,-1,1,11,10,1,4,11,1,0,4,7,11,4,-1,-1,-1,-1,4,7,8,9,0,11,9,11,10,11,0,3,-1,-1,-1,-1,4,7,11,4,11,9,9,11,10,-1,-1,-1,-1,-1,-1,-1,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,5,4,1,5,0,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,8,5,4,8,3,5,3,1,5,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,10,4,9,5,-1,-1,-1,-1,-1,-1,-1,5,2,10,5,4,2,4,0,2,-1,-1,-1,-1,-1,-1,-1,2,10,5,3,2,5,3,5,4,3,4,8,-1,-1,-1,-1,9,5,4,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,0,8,11,4,9,5,-1,-1,-1,-1,-1,-1,-1,0,5,4,0,1,5,2,3,11,-1,-1,-1,-1,-1,-1,-1,2,1,5,2,5,8,2,8,11,4,8,5,-1,-1,-1,-1,10,3,11,10,1,3,9,5,4,-1,-1,-1,-1,-1,-1,-1,4,9,5,0,8,1,8,10,1,8,11,10,-1,-1,-1,-1,5,4,0,5,0,11,5,11,10,11,0,3,-1,-1,-1,-1,5,4,8,5,
8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,9,7,8,5,7,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,3,0,9,5,3,5,7,3,-1,-1,-1,-1,-1,-1,-1,0,7,8,0,1,7,1,5,7,-1,-1,-1,-1,-1,-1,-1,1,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,7,8,9,5,7,10,1,2,-1,-1,-1,-1,-1,-1,-1,10,1,2,9,5,0,5,3,0,5,7,3,-1,-1,-1,-1,8,0,2,8,2,5,8,5,7,10,5,2,-1,-1,-1,-1,2,10,5,2,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,7,9,5,7,8,9,3,11,2,-1,-1,-1,-1,-1,-1,-1,9,5,7,9,7,2,9,2,0,2,7,11,-1,-1,-1,-1,2,3,11,0,1,8,1,7,8,1,5,7,-1,-1,-1,-1,11,2,1,11,1,7,7,1,5,-1,-1,-1,-1,-1,-1,
-1,9,5,8,8,5,7,10,1,3,10,3,11,-1,-1,-1,-1,5,7,0,5,0,9,7,11,0,1,0,10,11,10,0,-1,11,10,0,11,0,3,10,5,0,8,0,7,5,7,0,-1,11,10,5,7,11,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,0,1,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,1,9,8,5,10,6,-1,-1,-1,-1,-1,-1,-1,1,6,5,2,6,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,6,5,1,2,6,3,0,8,-1,-1,-1,-1,-1,-1,-1,9,6,5,9,0,6,0,2,6,-1,-1,-1,-1,-1,-1,-1,5,9,8,5,8,2,5,2,6,3,2,8,-1,-1,-1,-1,2,3,11,10,6,
5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,0,8,11,2,0,10,6,5,-1,-1,-1,-1,-1,-1,-1,0,1,9,2,3,11,5,10,6,-1,-1,-1,-1,-1,-1,-1,5,10,6,1,9,2,9,11,2,9,8,11,-1,-1,-1,-1,6,3,11,6,5,3,5,1,3,-1,-1,-1,-1,-1,-1,-1,0,8,11,0,11,5,0,5,1,5,11,6,-1,-1,-1,-1,3,11,6,0,3,6,0,6,5,0,5,9,-1,-1,-1,-1,6,5,9,6,9,11,11,9,8,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,4,7,3,6,5,10,-1,-1,-1,-1,-1,-1,-1,1,9,0,5,10,6,8,4,7,-1,-1,-1,-1,-1,-1,-1,10,6,5,1,9,7,1,7,3,7,9,4,-1,-1,-1,-1,6,1,2,6,5,1,4,7,8,-1,-1,-1,-1,
-1,-1,-1,1,2,5,5,2,6,3,0,4,3,4,7,-1,-1,-1,-1,8,4,7,9,0,5,0,6,5,0,2,6,-1,-1,-1,-1,7,3,9,7,9,4,3,2,9,5,9,6,2,6,9,-1,3,11,2,7,8,4,10,6,5,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,2,4,2,0,2,7,11,-1,-1,-1,-1,0,1,9,4,7,8,2,3,11,5,10,6,-1,-1,-1,-1,9,2,1,9,11,2,9,4,11,7,11,4,5,10,6,-1,8,4,7,3,11,5,3,5,1,5,11,6,-1,-1,-1,-1,5,1,11,5,11,6,1,0,11,7,11,4,0,4,11,-1,0,5,9,0,6,5,0,3,6,11,6,3,8,4,7,-1,6,5,9,6,9,11,4,7,9,7,11,9,-1,-1,-1,-1,10,4,9,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,10,6,4,9,10,0,8,3,-1,-1,-1,-1,-1,-1,-1,
10,0,1,10,6,0,6,4,0,-1,-1,-1,-1,-1,-1,-1,8,3,1,8,1,6,8,6,4,6,1,10,-1,-1,-1,-1,1,4,9,1,2,4,2,6,4,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,9,2,4,9,2,6,4,-1,-1,-1,-1,0,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,3,2,8,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,10,4,9,10,6,4,11,2,3,-1,-1,-1,-1,-1,-1,-1,0,8,2,2,8,11,4,9,10,4,10,6,-1,-1,-1,-1,3,11,2,0,1,6,0,6,4,6,1,10,-1,-1,-1,-1,6,4,1,6,1,10,4,8,1,2,1,11,8,11,1,-1,9,6,4,9,3,6,9,1,3,11,6,3,-1,-1,-1,-1,8,11,1,8,1,0,11,6,1,9,1,4,6,4,1,-1,3,11,6,3,6,0,0,6,4,-1,-1,-1,-1,-1,-1,-1,
6,4,8,11,6,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,10,6,7,8,10,8,9,10,-1,-1,-1,-1,-1,-1,-1,0,7,3,0,10,7,0,9,10,6,7,10,-1,-1,-1,-1,10,6,7,1,10,7,1,7,8,1,8,0,-1,-1,-1,-1,10,6,7,10,7,1,1,7,3,-1,-1,-1,-1,-1,-1,-1,1,2,6,1,6,8,1,8,9,8,6,7,-1,-1,-1,-1,2,6,9,2,9,1,6,7,9,0,9,3,7,3,9,-1,7,8,0,7,0,6,6,0,2,-1,-1,-1,-1,-1,-1,-1,7,3,2,6,7,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,11,10,6,8,10,8,9,8,6,7,-1,-1,-1,-1,2,0,7,2,7,11,0,9,7,6,7,10,9,10,7,-1,1,8,0,1,7,8,1,10,7,6,7,10,2,3,11,-1,11,2,1,11,1,7,10,6,1,6,7,1,-1,-1,-1,-1,
8,9,6,8,6,7,9,1,6,11,6,3,1,3,6,-1,0,9,1,11,6,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,8,0,7,0,6,3,11,0,11,6,0,-1,-1,-1,-1,7,11,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,1,9,8,3,1,11,7,6,-1,-1,-1,-1,-1,-1,-1,10,1,2,6,11,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,8,6,11,7,-1,-1,-1,-1,-1,-1,-1,2,9,0,2,10,9,6,11,7,-1,-1,-1,-1,-1,-1,-1,6,11,7,2,10,3,10,8,3,10,9,8,-1,-1,-1,-1,7,
2,3,6,2,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,0,8,7,6,0,6,2,0,-1,-1,-1,-1,-1,-1,-1,2,7,6,2,3,7,0,1,9,-1,-1,-1,-1,-1,-1,-1,1,6,2,1,8,6,1,9,8,8,7,6,-1,-1,-1,-1,10,7,6,10,1,7,1,3,7,-1,-1,-1,-1,-1,-1,-1,10,7,6,1,7,10,1,8,7,1,0,8,-1,-1,-1,-1,0,3,7,0,7,10,0,10,9,6,10,7,-1,-1,-1,-1,7,6,10,7,10,8,8,10,9,-1,-1,-1,-1,-1,-1,-1,6,8,4,11,8,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,6,11,3,0,6,0,4,6,-1,-1,-1,-1,-1,-1,-1,8,6,11,8,4,6,9,0,1,-1,-1,-1,-1,-1,-1,-1,9,4,6,9,6,3,9,3,1,11,3,6,-1,-1,-1,-1,6,8,4,6,11,8,2,10,1,-1,-1,-1,
-1,-1,-1,-1,1,2,10,3,0,11,0,6,11,0,4,6,-1,-1,-1,-1,4,11,8,4,6,11,0,2,9,2,10,9,-1,-1,-1,-1,10,9,3,10,3,2,9,4,3,11,3,6,4,6,3,-1,8,2,3,8,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,0,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,4,2,4,6,4,3,8,-1,-1,-1,-1,1,9,4,1,4,2,2,4,6,-1,-1,-1,-1,-1,-1,-1,8,1,3,8,6,1,8,4,6,6,10,1,-1,-1,-1,-1,10,1,0,10,0,6,6,0,4,-1,-1,-1,-1,-1,-1,-1,4,6,3,4,3,8,6,10,3,0,3,9,10,9,3,-1,10,9,4,6,10,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,5,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,5,11,7,6,
-1,-1,-1,-1,-1,-1,-1,5,0,1,5,4,0,7,6,11,-1,-1,-1,-1,-1,-1,-1,11,7,6,8,3,4,3,5,4,3,1,5,-1,-1,-1,-1,9,5,4,10,1,2,7,6,11,-1,-1,-1,-1,-1,-1,-1,6,11,7,1,2,10,0,8,3,4,9,5,-1,-1,-1,-1,7,6,11,5,4,10,4,2,10,4,0,2,-1,-1,-1,-1,3,4,8,3,5,4,3,2,5,10,5,2,11,7,6,-1,7,2,3,7,6,2,5,4,9,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,6,0,6,2,6,8,7,-1,-1,-1,-1,3,6,2,3,7,6,1,5,0,5,4,0,-1,-1,-1,-1,6,2,8,6,8,7,2,1,8,4,8,5,1,5,8,-1,9,5,4,10,1,6,1,7,6,1,3,7,-1,-1,-1,-1,1,6,10,1,7,6,1,0,7,8,7,0,9,5,4,-1,4,0,10,4,10,5,0,3,10,6,10,7,3,7,10,
-1,7,6,10,7,10,8,5,4,10,4,8,10,-1,-1,-1,-1,6,9,5,6,11,9,11,8,9,-1,-1,-1,-1,-1,-1,-1,3,6,11,0,6,3,0,5,6,0,9,5,-1,-1,-1,-1,0,11,8,0,5,11,0,1,5,5,6,11,-1,-1,-1,-1,6,11,3,6,3,5,5,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,11,9,11,8,11,5,6,-1,-1,-1,-1,0,11,3,0,6,11,0,9,6,5,6,9,1,2,10,-1,11,8,5,11,5,6,8,0,5,10,5,2,0,2,5,-1,6,11,3,6,3,5,2,10,3,10,5,3,-1,-1,-1,-1,5,8,9,5,2,8,5,6,2,3,8,2,-1,-1,-1,-1,9,5,6,9,6,0,0,6,2,-1,-1,-1,-1,-1,-1,-1,1,5,8,1,8,0,5,6,8,3,8,2,6,2,8,-1,1,5,6,2,1,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
1,3,6,1,6,10,3,8,6,5,6,9,8,9,6,-1,10,1,0,10,0,6,9,5,0,5,6,0,-1,-1,-1,-1,0,3,8,5,6,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,7,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,11,7,5,8,3,0,-1,-1,-1,-1,-1,-1,-1,5,11,7,5,10,11,1,9,0,-1,-1,-1,-1,-1,-1,-1,10,7,5,10,11,7,9,8,1,8,3,1,-1,-1,-1,-1,11,1,2,11,7,1,7,5,1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,7,1,7,5,7,2,11,-1,-1,-1,-1,9,7,5,9,2,7,9,0,2,2,11,7,-1,-1,-1,-1,7,5,2,7,2,11,5,9,2,3,2,8,9,8,2,-1,2,5,10,2,3,5,3,7,5,-1,-1,
-1,-1,-1,-1,-1,8,2,0,8,5,2,8,7,5,10,2,5,-1,-1,-1,-1,9,0,1,5,10,3,5,3,7,3,10,2,-1,-1,-1,-1,9,8,2,9,2,1,8,7,2,10,2,5,7,5,2,-1,1,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,7,0,7,1,1,7,5,-1,-1,-1,-1,-1,-1,-1,9,0,3,9,3,5,5,3,7,-1,-1,-1,-1,-1,-1,-1,9,8,7,5,9,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,5,8,4,5,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,5,0,4,5,11,0,5,10,11,11,3,0,-1,-1,-1,-1,0,1,9,8,4,10,8,10,11,10,4,5,-1,-1,-1,-1,10,11,4,10,4,5,11,3,4,9,4,1,3,1,4,-1,2,5,1,2,8,5,2,11,8,4,5,8,-1,-1,-1,-1,0,4,11,0,11,3,4,5,11,
2,11,1,5,1,11,-1,0,2,5,0,5,9,2,11,5,4,5,8,11,8,5,-1,9,4,5,2,11,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,5,10,3,5,2,3,4,5,3,8,4,-1,-1,-1,-1,5,10,2,5,2,4,4,2,0,-1,-1,-1,-1,-1,-1,-1,3,10,2,3,5,10,3,8,5,4,5,8,0,1,9,-1,5,10,2,5,2,4,1,9,2,9,4,2,-1,-1,-1,-1,8,4,5,8,5,3,3,5,1,-1,-1,-1,-1,-1,-1,-1,0,4,5,1,0,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,4,5,8,5,3,9,0,5,0,3,5,-1,-1,-1,-1,9,4,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,11,7,4,9,11,9,10,11,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,7,9,11,7,9,10,11,-1,-1,-1,-1,1,10,11,1,11,
4,1,4,0,7,4,11,-1,-1,-1,-1,3,1,4,3,4,8,1,10,4,7,4,11,10,11,4,-1,4,11,7,9,11,4,9,2,11,9,1,2,-1,-1,-1,-1,9,7,4,9,11,7,9,1,11,2,11,1,0,8,3,-1,11,7,4,11,4,2,2,4,0,-1,-1,-1,-1,-1,-1,-1,11,7,4,11,4,2,8,3,4,3,2,4,-1,-1,-1,-1,2,9,10,2,7,9,2,3,7,7,4,9,-1,-1,-1,-1,9,10,7,9,7,4,10,2,7,8,7,0,2,0,7,-1,3,7,10,3,10,2,7,4,10,1,10,0,4,0,10,-1,1,10,2,8,7,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,7,1,3,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,0,8,1,8,7,1,-1,-1,-1,-1,4,0,3,7,4,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,8,7,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,11,9,10,-1,-1,-1,-1,-1,-1,-1,0,1,10,0,10,8,8,10,11,-1,-1,-1,-1,-1,-1,-1,3,1,10,11,3,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,11,1,11,9,9,11,8,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,1,2,9,2,11,9,-1,-1,-1,-1,0,2,11,8,0,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,2,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,10,8,9,-1,-1,-1,-1,-1,-1,-1,9,10,2,0,9,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,0,1,8,1,10,8,-1,-1,-1,-1,1,10,
2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,8,9,1,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,9,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,3,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]);
M
Mr.doob 已提交
555 556
THREE.Trident=function(b){function c(c){return new THREE.Mesh(new THREE.CylinderGeometry(30,0.1,b.length/20,b.length/5),new THREE.MeshBasicMaterial({color:c}))}function e(b,c){var e=new THREE.Geometry;e.vertices=[new THREE.Vertex,new THREE.Vertex(b)];return new THREE.Line(e,new THREE.LineBasicMaterial({color:c}))}THREE.Object3D.call(this);var f=Math.PI/2,g,b=b||THREE.Trident.defaultParams;if(b!==THREE.Trident.defaultParams)for(g in THREE.Trident.defaultParams)b.hasOwnProperty(g)||(b[g]=THREE.Trident.defaultParams[g]);
this.scale=new THREE.Vector3(b.scale,b.scale,b.scale);this.addChild(e(new THREE.Vector3(b.length,0,0),b.xAxisColor));this.addChild(e(new THREE.Vector3(0,b.length,0),b.yAxisColor));this.addChild(e(new THREE.Vector3(0,0,b.length),b.zAxisColor));if(b.showArrows)g=c(b.xAxisColor),g.rotation.y=-f,g.position.x=b.length,this.addChild(g),g=c(b.yAxisColor),g.rotation.x=f,g.position.y=b.length,this.addChild(g),g=c(b.zAxisColor),g.rotation.y=Math.PI,g.position.z=b.length,this.addChild(g)};
557 558
THREE.Trident.prototype=new THREE.Object3D;THREE.Trident.prototype.constructor=THREE.Trident;THREE.Trident.defaultParams={xAxisColor:16711680,yAxisColor:65280,zAxisColor:255,showArrows:!0,length:100,scale:1};THREE.PlaneCollider=function(b,c){this.point=b;this.normal=c};THREE.SphereCollider=function(b,c){this.center=b;this.radius=c;this.radiusSq=c*c};THREE.BoxCollider=function(b,c){this.min=b;this.max=c;this.dynamic=!0;this.normal=new THREE.Vector3};
THREE.MeshCollider=function(b,c){this.mesh=b;this.box=c;this.numFaces=this.mesh.geometry.faces.length;this.normal=new THREE.Vector3};THREE.CollisionSystem=function(){this.collisionNormal=new THREE.Vector3;this.colliders=[];this.hits=[]};THREE.Collisions=new THREE.CollisionSystem;THREE.CollisionSystem.prototype.merge=function(b){this.colliders=this.colliders.concat(b.colliders);this.hits=this.hits.concat(b.hits)};
M
Mr.doob 已提交
559
THREE.CollisionSystem.prototype.rayCastAll=function(b){b.direction.normalize();this.hits.length=0;var c,e,f,g,k=0;c=0;for(e=this.colliders.length;c<e;c++)if(g=this.colliders[c],f=this.rayCast(b,g),f<Number.MAX_VALUE)g.distance=f,f>k?this.hits.push(g):this.hits.unshift(g),k=f;return this.hits};
M
Mr.doob 已提交
560
THREE.CollisionSystem.prototype.rayCastNearest=function(b){var c=this.rayCastAll(b);if(c.length==0)return null;for(var e=0;c[e]instanceof THREE.MeshCollider;){var f=this.rayMesh(b,c[e]);if(f.dist<Number.MAX_VALUE){c[e].distance=f.dist;c[e].faceIndex=f.faceIndex;break}e++}if(e>c.length)return null;return c[e]};
561
THREE.CollisionSystem.prototype.rayCast=function(b,c){if(c instanceof THREE.PlaneCollider)return this.rayPlane(b,c);else if(c instanceof THREE.SphereCollider)return this.raySphere(b,c);else if(c instanceof THREE.BoxCollider)return this.rayBox(b,c);else if(c instanceof THREE.MeshCollider&&c.box)return this.rayBox(b,c.box)};
562 563
THREE.CollisionSystem.prototype.rayMesh=function(b,c){for(var e=this.makeRayLocal(b,c.mesh),f=Number.MAX_VALUE,g,k=0;k<c.numFaces;k++){var h=c.mesh.geometry.faces[k],m=c.mesh.geometry.vertices[h.a].position,n=c.mesh.geometry.vertices[h.b].position,p=c.mesh.geometry.vertices[h.c].position,o=h instanceof THREE.Face4?c.mesh.geometry.vertices[h.d].position:null;h instanceof THREE.Face3?(h=this.rayTriangle(e,m,n,p,f,this.collisionNormal,c.mesh),h<f&&(f=h,g=k,c.normal.copy(this.collisionNormal),c.normal.normalize())):
h instanceof THREE.Face4&&(h=this.rayTriangle(e,m,n,o,f,this.collisionNormal,c.mesh),h<f&&(f=h,g=k,c.normal.copy(this.collisionNormal),c.normal.normalize()),h=this.rayTriangle(e,n,p,o,f,this.collisionNormal,c.mesh),h<f&&(f=h,g=k,c.normal.copy(this.collisionNormal),c.normal.normalize()))}return{dist:f,faceIndex:g}};
M
Mr.doob 已提交
564 565
THREE.CollisionSystem.prototype.rayTriangle=function(b,c,e,f,g,k,h){var m=THREE.CollisionSystem.__v1,n=THREE.CollisionSystem.__v2;k.set(0,0,0);m.sub(e,c);n.sub(f,e);k.cross(m,n);m=k.dot(b.direction);if(!(m<0))if(h.doubleSided||h.flipSided)k.multiplyScalar(-1),m*=-1;else return Number.MAX_VALUE;h=k.dot(c)-k.dot(b.origin);if(!(h<=0))return Number.MAX_VALUE;if(!(h>=m*g))return Number.MAX_VALUE;h/=m;m=THREE.CollisionSystem.__v3;m.copy(b.direction);m.multiplyScalar(h);m.addSelf(b.origin);Math.abs(k.x)>
Math.abs(k.y)?Math.abs(k.x)>Math.abs(k.z)?(b=m.y-c.y,k=e.y-c.y,g=f.y-c.y,m=m.z-c.z,e=e.z-c.z,f=f.z-c.z):(b=m.x-c.x,k=e.x-c.x,g=f.x-c.x,m=m.y-c.y,e=e.y-c.y,f=f.y-c.y):Math.abs(k.y)>Math.abs(k.z)?(b=m.x-c.x,k=e.x-c.x,g=f.x-c.x,m=m.z-c.z,e=e.z-c.z,f=f.z-c.z):(b=m.x-c.x,k=e.x-c.x,g=f.x-c.x,m=m.y-c.y,e=e.y-c.y,f=f.y-c.y);c=k*f-e*g;if(c==0)return Number.MAX_VALUE;c=1/c;f=(b*f-m*g)*c;if(!(f>=0))return Number.MAX_VALUE;c*=k*m-e*b;if(!(c>=0))return Number.MAX_VALUE;if(!(1-f-c>=0))return Number.MAX_VALUE;return h};
M
Mr.doob 已提交
566
THREE.CollisionSystem.prototype.makeRayLocal=function(b,c){var e=THREE.CollisionSystem.__m;THREE.Matrix4.makeInvert(c.matrixWorld,e);var f=THREE.CollisionSystem.__r;f.origin.copy(b.origin);f.direction.copy(b.direction);e.multiplyVector3(f.origin);e.rotateAxis(f.direction);f.direction.normalize();return f};
567 568
THREE.CollisionSystem.prototype.rayBox=function(b,c){var e;c.dynamic&&c.mesh&&c.mesh.matrixWorld?e=this.makeRayLocal(b,c.mesh):(e=THREE.CollisionSystem.__r,e.origin.copy(b.origin),e.direction.copy(b.direction));var f=0,g=0,k=0,h=0,m=0,n=0,p=!0;e.origin.x<c.min.x?(f=c.min.x-e.origin.x,f/=e.direction.x,p=!1,h=-1):e.origin.x>c.max.x&&(f=c.max.x-e.origin.x,f/=e.direction.x,p=!1,h=1);e.origin.y<c.min.y?(g=c.min.y-e.origin.y,g/=e.direction.y,p=!1,m=-1):e.origin.y>c.max.y&&(g=c.max.y-e.origin.y,g/=e.direction.y,
p=!1,m=1);e.origin.z<c.min.z?(k=c.min.z-e.origin.z,k/=e.direction.z,p=!1,n=-1):e.origin.z>c.max.z&&(k=c.max.z-e.origin.z,k/=e.direction.z,p=!1,n=1);if(p)return-1;p=0;g>f&&(p=1,f=g);k>f&&(p=2,f=k);switch(p){case 0:m=e.origin.y+e.direction.y*f;if(m<c.min.y||m>c.max.y)return Number.MAX_VALUE;e=e.origin.z+e.direction.z*f;if(e<c.min.z||e>c.max.z)return Number.MAX_VALUE;c.normal.set(h,0,0);break;case 1:h=e.origin.x+e.direction.x*f;if(h<c.min.x||h>c.max.x)return Number.MAX_VALUE;e=e.origin.z+e.direction.z*
M
Mr.doob 已提交
569
f;if(e<c.min.z||e>c.max.z)return Number.MAX_VALUE;c.normal.set(0,m,0);break;case 2:h=e.origin.x+e.direction.x*f;if(h<c.min.x||h>c.max.x)return Number.MAX_VALUE;m=e.origin.y+e.direction.y*f;if(m<c.min.y||m>c.max.y)return Number.MAX_VALUE;c.normal.set(0,0,n)}return f};THREE.CollisionSystem.prototype.rayPlane=function(b,c){var e=b.direction.dot(c.normal),f=c.point.dot(c.normal);if(e<0)e=(f-b.origin.dot(c.normal))/e;else return Number.MAX_VALUE;return e>0?e:Number.MAX_VALUE};
M
Mr.doob 已提交
570 571
THREE.CollisionSystem.prototype.raySphere=function(b,c){var e=c.center.clone().subSelf(b.origin);if(e.lengthSq<c.radiusSq)return-1;var f=e.dot(b.direction.clone());if(f<=0)return Number.MAX_VALUE;e=c.radiusSq-(e.lengthSq()-f*f);if(e>=0)return Math.abs(f)-Math.sqrt(e);return Number.MAX_VALUE};THREE.CollisionSystem.__v1=new THREE.Vector3;THREE.CollisionSystem.__v2=new THREE.Vector3;THREE.CollisionSystem.__v3=new THREE.Vector3;THREE.CollisionSystem.__nr=new THREE.Vector3;THREE.CollisionSystem.__m=new THREE.Matrix4;
THREE.CollisionSystem.__r=new THREE.Ray;THREE.CollisionUtils={};THREE.CollisionUtils.MeshOBB=function(b){b.geometry.computeBoundingBox();var c=b.geometry.boundingBox,e=new THREE.Vector3(c.x[0],c.y[0],c.z[0]),c=new THREE.Vector3(c.x[1],c.y[1],c.z[1]),e=new THREE.BoxCollider(e,c);e.mesh=b;return e};THREE.CollisionUtils.MeshAABB=function(b){var c=THREE.CollisionUtils.MeshOBB(b);c.min.addSelf(b.position);c.max.addSelf(b.position);c.dynamic=!1;return c};
572
THREE.CollisionUtils.MeshColliderWBox=function(b){return new THREE.MeshCollider(b,THREE.CollisionUtils.MeshOBB(b))};
573
if(THREE.WebGLRenderer)THREE.AnaglyphWebGLRenderer=function(b){THREE.WebGLRenderer.call(this,b);var c=this,e=this.setSize,f=this.render,g=new THREE.Camera,k=new THREE.Camera,h=new THREE.Matrix4,m=new THREE.Matrix4,n,p,o;g.useTarget=k.useTarget=!1;g.matrixAutoUpdate=k.matrixAutoUpdate=!1;var b={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat},t=new THREE.WebGLRenderTarget(512,512,b),v=new THREE.WebGLRenderTarget(512,512,b),u=new THREE.Camera(53,1,1,1E4);u.position.z=
M
Mr.doob 已提交
574
2;_material=new THREE.MeshShaderMaterial({uniforms:{mapLeft:{type:"t",value:0,texture:t},mapRight:{type:"t",value:1,texture:v}},vertexShader:"varying vec2 vUv;\nvoid main() {\nvUv = vec2( uv.x, 1.0 - uv.y );\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D mapLeft;\nuniform sampler2D mapRight;\nvarying vec2 vUv;\nvoid main() {\nvec4 colorL, colorR;\nvec2 uv = vUv;\ncolorL = texture2D( mapLeft, uv );\ncolorR = texture2D( mapRight, uv );\ngl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;\n}"});
575 576
var w=new THREE.Scene;w.addObject(new THREE.Mesh(new THREE.PlaneGeometry(2,2),_material));this.setSize=function(b,f){e.call(c,b,f);t.width=b;t.height=f;v.width=b;v.height=f};this.render=function(b,e){e.update(null,!0);if(n!==e.aspect||p!==e.near||o!==e.fov){n=e.aspect;p=e.near;o=e.fov;var y=e.projectionMatrix.clone(),G=125/30*0.5,z=G*p/125,C=p*Math.tan(o*Math.PI/360),H;h.n14=G;m.n14=-G;G=-C*n+z;H=C*n+z;y.n11=2*p/(H-G);y.n13=(H+G)/(H-G);g.projectionMatrix=y.clone();G=-C*n-z;H=C*n-z;y.n11=2*p/(H-G);
y.n13=(H+G)/(H-G);k.projectionMatrix=y.clone()}g.matrix=e.matrixWorld.clone().multiplySelf(m);g.update(null,!0);g.position.copy(e.position);g.near=p;g.far=e.far;f.call(c,b,g,t,!0);k.matrix=e.matrixWorld.clone().multiplySelf(h);k.update(null,!0);k.position.copy(e.position);k.near=p;k.far=e.far;f.call(c,b,k,v,!0);f.call(c,w,u)}};
M
Mr.doob 已提交
577 578
if(THREE.WebGLRenderer)THREE.CrosseyedWebGLRenderer=function(b){THREE.WebGLRenderer.call(this,b);this.autoClear=!1;var c=this,e=this.setSize,f=this.render,g,k,h=new THREE.Camera,m=new THREE.Camera;c.separation=10;if(b&&b.separation!==void 0)c.separation=b.separation;(new THREE.Camera(53,window.innerWidth/2/window.innerHeight,1,1E4)).position.z=-10;this.setSize=function(b,f){e.call(c,b,f);g=b/2;k=f};this.render=function(b,e){this.clear();h.fov=e.fov;h.aspect=0.5*e.aspect;h.near=e.near;h.far=e.far;
h.updateProjectionMatrix();h.position.copy(e.position);h.target.position.copy(e.target.position);h.translateX(c.separation);m.projectionMatrix=h.projectionMatrix;m.position.copy(e.position);m.target.position.copy(e.target.position);m.translateX(-c.separation);this.setViewport(0,0,g,k);f.call(c,b,h);this.setViewport(g,0,g,k);f.call(c,b,m,!1)}};