ThreeExtras.js 105.2 KB
Newer Older
A
alteredq 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// ThreeExtras.js r31 - http://github.com/mrdoob/three.js
var THREE=THREE||{};THREE.Color=function(a){this.autoUpdate=true;this.setHex(a)};
THREE.Color.prototype={setRGB:function(a,b,d){this.r=a;this.g=b;this.b=d;if(this.autoUpdate){this.updateHex();this.updateStyleString()}},setHex:function(a){this.hex=~~a&16777215;if(this.autoUpdate){this.updateRGBA();this.updateStyleString()}},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGBA:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},updateStyleString:function(){this.__styleString="rgb("+~~(this.r*255)+
","+~~(this.g*255)+","+~~(this.b*255)+")"},toString:function(){return"THREE.Color ( r: "+this.r+", g: "+this.g+", b: "+this.b+", hex: "+this.hex+" )"}};THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0};
THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},unit:function(){this.multiplyScalar(1/this.length());return this},length:function(){return Math.sqrt(this.x*
this.x+this.y*this.y)},lengthSq:function(){return this.x*this.x+this.y*this.y},negate:function(){this.x=-this.x;this.y=-this.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},toString:function(){return"THREE.Vector2 ("+this.x+", "+this.y+")"}};THREE.Vector3=function(a,b,d){this.x=a||0;this.y=b||0;this.z=d||0};
THREE.Vector3.prototype={set:function(a,b,d){this.x=a;this.y=b;this.z=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,e=this.z;this.x=d*a.z-e*a.y;this.y=e*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+d*d+a*a)},distanceToSquared:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return b*b+d*d+a*a},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},negate:function(){this.x=-this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=
Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<1.0E-4&&Math.abs(this.y)<1.0E-4&&Math.abs(this.z)<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},toString:function(){return"THREE.Vector3 ( "+this.x+", "+this.y+", "+this.z+" )"}};
THREE.Vector4=function(a,b,d,e){this.x=a||0;this.y=b||0;this.z=d||0;this.w=e||1};
THREE.Vector4.prototype={set:function(a,b,d,e){this.x=a;this.y=b;this.z=d;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
A
alteredq 已提交
15 16 17 18
THREE.Ray.prototype={intersectScene:function(a){var b,d,e=a.objects,f=[];a=0;for(b=e.length;a<b;a++){d=e[a];if(d instanceof THREE.Mesh)f=f.concat(this.intersectObject(d))}f.sort(function(k,l){return k.distance-l.distance});return f},intersectObject:function(a){function b(K,F,y,o){o=o.clone().subSelf(F);y=y.clone().subSelf(F);var i=K.clone().subSelf(F);K=o.dot(o);F=o.dot(y);o=o.dot(i);var p=y.dot(y);y=y.dot(i);i=1/(K*p-F*F);p=(p*o-F*y)*i;K=(K*y-F*o)*i;return p>0&&K>0&&p+K<1}var d,e,f,k,l,g,j,c,t,x,
q,s=a.geometry,v=s.vertices,z=[];d=0;for(e=s.faces.length;d<e;d++){f=s.faces[d];x=this.origin.clone();q=this.direction.clone();k=a.matrix.multiplyVector3(v[f.a].position.clone());l=a.matrix.multiplyVector3(v[f.b].position.clone());g=a.matrix.multiplyVector3(v[f.c].position.clone());j=f instanceof THREE.Face4?a.matrix.multiplyVector3(v[f.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(f.normal.clone());t=q.dot(c);if(t<0){c=c.dot((new THREE.Vector3).sub(k,x))/t;x=x.addSelf(q.multiplyScalar(c));
if(f instanceof THREE.Face3){if(b(x,k,l,g)){f={distance:this.origin.distanceTo(x),point:x,face:f,object:a};z.push(f)}}else if(f instanceof THREE.Face4)if(b(x,k,l,j)||b(x,l,g,j)){f={distance:this.origin.distanceTo(x),point:x,face:f,object:a};z.push(f)}}}return z}};
THREE.Rectangle=function(){function a(){k=e-b;l=f-d}var b,d,e,f,k,l,g=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return k};this.getHeight=function(){return l};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return e};this.getBottom=function(){return f};this.set=function(j,c,t,x){g=false;b=j;d=c;e=t;f=x;a()};this.addPoint=function(j,c){if(g){g=false;b=j;d=c;e=j;f=c}else{b=b<j?b:j;d=d<c?d:c;e=e>j?e:j;f=f>c?
A
alteredq 已提交
19 20
f:c}a()};this.add3Points=function(j,c,t,x,q,s){if(g){g=false;b=j<t?j<q?j:q:t<q?t:q;d=c<x?c<s?c:s:x<s?x:s;e=j>t?j>q?j:q:t>q?t:q;f=c>x?c>s?c:s:x>s?x:s}else{b=j<t?j<q?j<b?j:b:q<b?q:b:t<q?t<b?t:b:q<b?q:b;d=c<x?c<s?c<d?c:d:s<d?s:d:x<s?x<d?x:d:s<d?s:d;e=j>t?j>q?j>e?j:e:q>e?q:e:t>q?t>e?t:e:q>e?q:e;f=c>x?c>s?c>f?c:f:s>f?s:f:x>s?x>f?x:f:s>f?s:f}a()};this.addRectangle=function(j){if(g){g=false;b=j.getLeft();d=j.getTop();e=j.getRight();f=j.getBottom()}else{b=b<j.getLeft()?b:j.getLeft();d=d<j.getTop()?d:j.getTop();
e=e>j.getRight()?e:j.getRight();f=f>j.getBottom()?f:j.getBottom()}a()};this.inflate=function(j){b-=j;d-=j;e+=j;f+=j;a()};this.minSelf=function(j){b=b>j.getLeft()?b:j.getLeft();d=d>j.getTop()?d:j.getTop();e=e<j.getRight()?e:j.getRight();f=f<j.getBottom()?f:j.getBottom();a()};this.instersects=function(j){return Math.min(e,j.getRight())-Math.max(b,j.getLeft())>=0&&Math.min(f,j.getBottom())-Math.max(d,j.getTop())>=0};this.empty=function(){g=true;f=e=d=b=0;a()};this.isEmpty=function(){return g};this.toString=
A
alteredq 已提交
21 22 23
function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+d+", bottom: "+f+", width: "+k+", height: "+l+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
THREE.Matrix4=function(a,b,d,e,f,k,l,g,j,c,t,x,q,s,v,z){this.n11=a||1;this.n12=b||0;this.n13=d||0;this.n14=e||0;this.n21=f||0;this.n22=k||1;this.n23=l||0;this.n24=g||0;this.n31=j||0;this.n32=c||0;this.n33=t||1;this.n34=x||0;this.n41=q||0;this.n42=s||0;this.n43=v||0;this.n44=z||1};
THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,d,e,f,k,l,g,j,c,t,x,q,s,v,z){this.n11=a;this.n12=b;this.n13=d;this.n14=e;this.n21=f;this.n22=k;this.n23=l;this.n24=g;this.n31=j;this.n32=c;this.n33=t;this.n34=x;this.n41=q;this.n42=s;this.n43=v;this.n44=z;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
A
alteredq 已提交
24 25
a.n13;this.n14=a.n14;this.n21=a.n21;this.n22=a.n22;this.n23=a.n23;this.n24=a.n24;this.n31=a.n31;this.n32=a.n32;this.n33=a.n33;this.n34=a.n34;this.n41=a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44;return this},lookAt:function(a,b,d){var e=new THREE.Vector3,f=new THREE.Vector3,k=new THREE.Vector3;k.sub(a,b).normalize();e.cross(d,k).normalize();f.cross(k,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=f.x;this.n22=f.y;this.n23=f.z;this.n24=-f.dot(a);this.n31=k.x;
this.n32=k.y;this.n33=k.z;this.n34=-k.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,d=a.y,e=a.z,f=1/(this.n41*b+this.n42*d+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*e+this.n14)*f;a.y=(this.n21*b+this.n22*d+this.n23*e+this.n24)*f;a.z=(this.n31*b+this.n32*d+this.n33*e+this.n34)*f;return a},multiplyVector4:function(a){var b=a.x,d=a.y,e=a.z,f=a.w;a.x=this.n11*b+this.n12*d+this.n13*e+this.n14*f;a.y=this.n21*b+this.n22*d+this.n23*e+this.n24*
A
alteredq 已提交
26 27 28 29
f;a.z=this.n31*b+this.n32*d+this.n33*e+this.n34*f;a.w=this.n41*b+this.n42*d+this.n43*e+this.n44*f;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,e=a.n12,f=a.n13,k=a.n14,l=a.n21,g=a.n22,j=a.n23,c=a.n24,t=a.n31,x=a.n32,
q=a.n33,s=a.n34,v=a.n41,z=a.n42,K=a.n43,F=a.n44,y=b.n11,o=b.n12,i=b.n13,p=b.n14,h=b.n21,w=b.n22,m=b.n23,n=b.n24,D=b.n31,A=b.n32,L=b.n33,E=b.n34,O=b.n41,S=b.n42,G=b.n43,T=b.n44;this.n11=d*y+e*h+f*D+k*O;this.n12=d*o+e*w+f*A+k*S;this.n13=d*i+e*m+f*L+k*G;this.n14=d*p+e*n+f*E+k*T;this.n21=l*y+g*h+j*D+c*O;this.n22=l*o+g*w+j*A+c*S;this.n23=l*i+g*m+j*L+c*G;this.n24=l*p+g*n+j*E+c*T;this.n31=t*y+x*h+q*D+s*O;this.n32=t*o+x*w+q*A+s*S;this.n33=t*i+x*m+q*L+s*G;this.n34=t*p+x*n+q*E+s*T;this.n41=v*y+z*h+K*D+F*O;
this.n42=v*o+z*w+K*A+F*S;this.n43=v*i+z*m+K*L+F*G;this.n44=v*p+z*n+K*E+F*T;return this},multiplySelf:function(a){var b=this.n11,d=this.n12,e=this.n13,f=this.n14,k=this.n21,l=this.n22,g=this.n23,j=this.n24,c=this.n31,t=this.n32,x=this.n33,q=this.n34,s=this.n41,v=this.n42,z=this.n43,K=this.n44,F=a.n11,y=a.n21,o=a.n31,i=a.n41,p=a.n12,h=a.n22,w=a.n32,m=a.n42,n=a.n13,D=a.n23,A=a.n33,L=a.n43,E=a.n14,O=a.n24,S=a.n34;a=a.n44;this.n11=b*F+d*y+e*o+f*i;this.n12=b*p+d*h+e*w+f*m;this.n13=b*n+d*D+e*A+f*L;this.n14=
b*E+d*O+e*S+f*a;this.n21=k*F+l*y+g*o+j*i;this.n22=k*p+l*h+g*w+j*m;this.n23=k*n+l*D+g*A+j*L;this.n24=k*E+l*O+g*S+j*a;this.n31=c*F+t*y+x*o+q*i;this.n32=c*p+t*h+x*w+q*m;this.n33=c*n+t*D+x*A+q*L;this.n34=c*E+t*O+x*S+q*a;this.n41=s*F+v*y+z*o+K*i;this.n42=s*p+v*h+z*w+K*m;this.n43=s*n+v*D+z*A+K*L;this.n44=s*E+v*O+z*S+K*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
A
alteredq 已提交
30 31 32 33 34
a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){return this.n14*this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*
this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,e){var f=b[d];b[d]=b[e];
b[e]=f}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){return[this.n11,this.n21,this.n31,this.n41,this.n12,
this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var e=new THREE.Matrix4;e.n14=a;e.n24=b;e.n34=d;return e};
THREE.Matrix4.scaleMatrix=function(a,b,d){var e=new THREE.Matrix4;e.n11=a;e.n22=b;e.n33=d;return e};THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
A
alteredq 已提交
35
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,e=Math.cos(b),f=Math.sin(b),k=1-e,l=a.x,g=a.y,j=a.z;d.n11=k*l*l+e;d.n12=k*l*g-f*j;d.n13=k*l*j+f*g;d.n21=k*l*g+f*j;d.n22=k*g*g+e;d.n23=k*g*j-f*l;d.n31=k*l*j-f*g;d.n32=k*g*j+f*l;d.n33=k*j*j+e;return d};
A
alteredq 已提交
36 37 38 39
THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a.n42-a.n24*a.n33*a.n42+a.n24*a.n32*a.n43-a.n22*a.n34*a.n43-a.n23*a.n32*a.n44+a.n22*a.n33*a.n44;b.n12=a.n14*a.n33*a.n42-a.n13*a.n34*a.n42-a.n14*a.n32*a.n43+a.n12*a.n34*a.n43+a.n13*a.n32*a.n44-a.n12*a.n33*a.n44;b.n13=a.n13*a.n24*a.n42-a.n14*a.n23*a.n42+a.n14*a.n22*a.n43-a.n12*a.n24*a.n43-a.n13*a.n22*a.n44+a.n12*a.n23*a.n44;b.n14=a.n14*a.n23*a.n32-a.n13*a.n24*a.n32-a.n14*a.n22*a.n33+a.n12*a.n24*a.n33+a.n13*a.n22*a.n34-a.n12*
a.n23*a.n34;b.n21=a.n24*a.n33*a.n41-a.n23*a.n34*a.n41-a.n24*a.n31*a.n43+a.n21*a.n34*a.n43+a.n23*a.n31*a.n44-a.n21*a.n33*a.n44;b.n22=a.n13*a.n34*a.n41-a.n14*a.n33*a.n41+a.n14*a.n31*a.n43-a.n11*a.n34*a.n43-a.n13*a.n31*a.n44+a.n11*a.n33*a.n44;b.n23=a.n14*a.n23*a.n41-a.n13*a.n24*a.n41-a.n14*a.n21*a.n43+a.n11*a.n24*a.n43+a.n13*a.n21*a.n44-a.n11*a.n23*a.n44;b.n24=a.n13*a.n24*a.n31-a.n14*a.n23*a.n31+a.n14*a.n21*a.n33-a.n11*a.n24*a.n33-a.n13*a.n21*a.n34+a.n11*a.n23*a.n34;b.n31=a.n22*a.n34*a.n41-a.n24*a.n32*
a.n41+a.n24*a.n31*a.n42-a.n21*a.n34*a.n42-a.n22*a.n31*a.n44+a.n21*a.n32*a.n44;b.n32=a.n14*a.n32*a.n41-a.n12*a.n34*a.n41-a.n14*a.n31*a.n42+a.n11*a.n34*a.n42+a.n12*a.n31*a.n44-a.n11*a.n32*a.n44;b.n33=a.n13*a.n24*a.n41-a.n14*a.n22*a.n41+a.n14*a.n21*a.n42-a.n11*a.n24*a.n42-a.n12*a.n21*a.n44+a.n11*a.n22*a.n44;b.n34=a.n14*a.n22*a.n31-a.n12*a.n24*a.n31-a.n14*a.n21*a.n32+a.n11*a.n24*a.n32+a.n12*a.n21*a.n34-a.n11*a.n22*a.n34;b.n41=a.n23*a.n32*a.n41-a.n22*a.n33*a.n41-a.n23*a.n31*a.n42+a.n21*a.n33*a.n42+a.n22*
a.n31*a.n43-a.n21*a.n32*a.n43;b.n42=a.n12*a.n33*a.n41-a.n13*a.n32*a.n41+a.n13*a.n31*a.n42-a.n11*a.n33*a.n42-a.n12*a.n31*a.n43+a.n11*a.n32*a.n43;b.n43=a.n13*a.n22*a.n41-a.n12*a.n23*a.n41-a.n13*a.n21*a.n42+a.n11*a.n23*a.n42+a.n12*a.n21*a.n43-a.n11*a.n22*a.n43;b.n44=a.n12*a.n23*a.n31-a.n13*a.n22*a.n31+a.n13*a.n21*a.n32-a.n11*a.n23*a.n32-a.n12*a.n21*a.n33+a.n11*a.n22*a.n33;b.multiplyScalar(1/a.determinant());return b};
A
alteredq 已提交
40 41 42
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],f=b[6]*b[1]-b[2]*b[5],k=-b[10]*b[4]+b[6]*b[8],l=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],j=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],t=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*k+b[2]*j;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*e;a.m[2]=b*f;a.m[3]=b*k;a.m[4]=b*l;a.m[5]=b*g;a.m[6]=b*j;a.m[7]=b*c;a.m[8]=b*t;return a};
THREE.Matrix4.makeFrustum=function(a,b,d,e,f,k){var l,g,j;l=new THREE.Matrix4;g=2*f/(b-a);j=2*f/(e-d);a=(b+a)/(b-a);d=(e+d)/(e-d);e=-(k+f)/(k-f);f=-2*k*f/(k-f);l.n11=g;l.n12=0;l.n13=a;l.n14=0;l.n21=0;l.n22=j;l.n23=d;l.n24=0;l.n31=0;l.n32=0;l.n33=e;l.n34=f;l.n41=0;l.n42=0;l.n43=-1;l.n44=0;return l};THREE.Matrix4.makePerspective=function(a,b,d,e){var f;a=d*Math.tan(a*Math.PI/360);f=-a;return THREE.Matrix4.makeFrustum(f*b,a*b,f,a,d,e)};
THREE.Matrix4.makeOrtho=function(a,b,d,e,f,k){var l,g,j,c;l=new THREE.Matrix4;g=b-a;j=d-e;c=k-f;a=(b+a)/g;d=(d+e)/j;f=(k+f)/c;l.n11=2/g;l.n12=0;l.n13=0;l.n14=-a;l.n21=0;l.n22=2/j;l.n23=0;l.n24=-d;l.n31=0;l.n32=0;l.n33=-2/c;l.n34=-f;l.n41=0;l.n42=0;l.n43=0;l.n44=1;return l};
A
alteredq 已提交
43 44 45 46 47
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
THREE.Face3=function(a,b,d,e,f){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.material=f instanceof Array?f:[f]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
THREE.Face4=function(a,b,d,e,f,k){this.a=a;this.b=b;this.c=d;this.d=e;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.material=k instanceof Array?k:[k]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={};this.hasTangents=false};
THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
A
alteredq 已提交
48
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,d,e,f,k,l,g=new THREE.Vector3,j=new THREE.Vector3;e=0;for(f=this.vertices.length;e<f;e++){k=this.vertices[e];k.normal.set(0,0,0)}e=0;for(f=this.faces.length;e<f;e++){k=this.faces[e];if(a&&k.vertexNormals.length){g.set(0,0,0);b=0;for(d=k.normal.length;b<d;b++)g.addSelf(k.vertexNormals[b]);g.divideScalar(3)}else{b=this.vertices[k.a];d=this.vertices[k.b];l=this.vertices[k.c];g.sub(l.position,
A
alteredq 已提交
49
d.position);j.sub(b.position,d.position);g.crossSelf(j)}g.isZero()||g.normalize();k.normal.copy(g)}},computeVertexNormals:function(){var a,b=[],d,e;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){e=this.faces[a];if(e instanceof THREE.Face3){b[e.a].addSelf(e.normal);b[e.b].addSelf(e.normal);b[e.c].addSelf(e.normal)}else if(e instanceof THREE.Face4){b[e.a].addSelf(e.normal);b[e.b].addSelf(e.normal);b[e.c].addSelf(e.normal);b[e.d].addSelf(e.normal)}}a=
A
alteredq 已提交
50 51 52 53
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=b[e.a].clone();e.vertexNormals[1]=b[e.b].clone();e.vertexNormals[2]=b[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=b[e.a].clone();e.vertexNormals[1]=b[e.b].clone();e.vertexNormals[2]=b[e.c].clone();e.vertexNormals[3]=b[e.d].clone()}}},computeTangents:function(){function a(E,O,S,G){k=E.vertices[O].position;l=E.vertices[S].position;
g=E.vertices[G].position;j=f[0];c=f[1];t=f[2];x=l.x-k.x;q=g.x-k.x;s=l.y-k.y;v=g.y-k.y;z=l.z-k.z;K=g.z-k.z;F=c.u-j.u;y=t.u-j.u;o=c.v-j.v;i=t.v-j.v;p=1/(F*i-y*o);n.set((i*x-o*q)*p,(i*s-o*v)*p,(i*z-o*K)*p);D.set((F*q-y*x)*p,(F*v-y*s)*p,(F*K-y*z)*p);w[O].addSelf(n);w[S].addSelf(n);w[G].addSelf(n);m[O].addSelf(D);m[S].addSelf(D);m[G].addSelf(D)}var b,d,e,f,k,l,g,j,c,t,x,q,s,v,z,K,F,y,o,i,p,h,w=[],m=[],n=new THREE.Vector3,D=new THREE.Vector3,A=new THREE.Vector3,L=new THREE.Vector3;h=new THREE.Vector3;b=
0;for(d=this.vertices.length;b<d;b++){w[b]=new THREE.Vector3;m[b]=new THREE.Vector3}b=0;for(d=this.faces.length;b<d;b++){e=this.faces[b];f=this.uvs[b];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);
this.vertices[e.c].normal.copy(e.vertexNormals[2]);this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(d=this.vertices.length;b<d;b++){h.copy(this.vertices[b].normal);e=w[b];A.copy(e);A.subSelf(h.multiplyScalar(h.dot(e))).normalize();L.cross(this.vertices[b].normal,e);test=L.dot(m[b]);e=test<0?-1:1;this.vertices[b].tangent.set(A.x,A.y,A.z,e)}this.hasTangents=true},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
A
alteredq 已提交
54
y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=
A
alteredq 已提交
55 56
vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(t){var x=[];b=0;for(d=t.length;b<d;b++)t[b]==undefined?x.push("undefined"):x.push(t[b].toString());return x.join("_")}var b,d,e,f,k,l,g,j,c={};e=0;for(f=this.faces.length;e<f;e++){k=this.faces[e];l=k.material;g=a(l);if(c[g]==undefined)c[g]={hash:g,counter:0};j=c[g].hash+"_"+c[g].counter;if(this.geometryChunks[j]==undefined)this.geometryChunks[j]={faces:[],material:l,
vertices:0};k=k instanceof THREE.Face3?3:4;if(this.geometryChunks[j].vertices+k>65535){c[g].counter+=1;j=c[g].hash+"_"+c[g].counter;if(this.geometryChunks[j]==undefined)this.geometryChunks[j]={faces:[],material:l,vertices:0}}this.geometryChunks[j].faces.push(e);this.geometryChunks[j].vertices+=k}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
A
alteredq 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
THREE.Camera=function(a,b,d,e){this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,e);this.autoUpdateMatrix=true;this.translateX=function(f){f=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(f);f.cross(f.clone(),this.up);this.position.addSelf(f);this.target.position.addSelf(f)};this.translateZ=function(f){f=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(f);
this.position.subSelf(f);this.target.position.subSelf(f)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;
THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
THREE.Object3D=function(){this.id=THREE.Object3DCounter.value++;this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.matrix=new THREE.Matrix4;this.translationMatrix=new THREE.Matrix4;this.rotationMatrix=new THREE.Matrix4;this.scaleMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.autoUpdateMatrix=this.visible=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);
this.rotationMatrix=THREE.Matrix4.rotationXMatrix(this.rotation.x);this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.scaleMatrix=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);this.matrix.multiplySelf(this.rotationMatrix);this.matrix.multiplySelf(this.scaleMatrix)}};THREE.Object3DCounter={value:0};
THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.Line=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
THREE.Mesh=function(a,b,d){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;d&&this.normalizeUVs();this.geometry.computeBoundingBox()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;
THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,e,f;a=0;for(b=this.geometry.uvs.length;a<b;a++){f=this.geometry.uvs[a];d=0;for(e=f.length;d<e;d++){if(f[d].u!=1)f[d].u-=Math.floor(f[d].u);if(f[d].v!=1)f[d].v-=Math.floor(f[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;this.linewidth=1;this.linejoin=this.linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.linewidth!==undefined)this.linewidth=a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+
this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(15658734);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=
a.map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=
a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin}this.toString=function(){return"THREE.MeshBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>blending: "+
this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>)"}};THREE.MeshBasicMaterialCounter={value:0};
THREE.MeshLambertMaterial=function(a){this.id=THREE.MeshLambertMaterialCounter.value++;this.color=new THREE.Color(15658734);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=
a.map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=
a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin}this.toString=function(){return"THREE.MeshLambertMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+
this.shading+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/> )"}};THREE.MeshLambertMaterialCounter={value:0};
THREE.MeshPhongMaterial=function(a){this.id=THREE.MeshPhongMaterialCounter.value++;this.color=new THREE.Color(15658734);this.ambient=new THREE.Color(328965);this.specular=new THREE.Color(1118481);this.shininess=30;this.env_map=this.specular_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap=
"round";if(a){if(a.color!==undefined)this.color=new THREE.Color(a.color);if(a.ambient!==undefined)this.ambient=new THREE.Color(a.ambient);if(a.specular!==undefined)this.specular=new THREE.Color(a.specular);if(a.shininess!==undefined)this.shininess=a.shininess;if(a.map!==undefined)this.map=a.map;if(a.specular_map!==undefined)this.specular_map=a.specular_map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=
a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=
a.wireframe_linejoin}this.toString=function(){return"THREE.MeshPhongMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>ambient: "+this.ambient+"<br/>specular: "+this.specular+"<br/>shininess: "+this.shininess+"<br/>map: "+this.map+"<br/>specular_map: "+this.specular_map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>wireframe: "+
this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>"+ +")"}};THREE.MeshPhongMaterialCounter={value:0};
THREE.MeshDepthMaterial=function(a){this.near=1;this.far=1E3;this.opacity=1;this.blending=THREE.NormalBlending;if(a){if(a.near!==undefined)this.near=a.near;if(a.far!==undefined)this.far=a.far;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.__2near=2*this.near;this.__farPlusNear=this.far+this.near;this.__farMinusNear=this.far-this.near;this.toString=function(){return"THREE.MeshDepthMaterial"}};
THREE.MeshNormalMaterial=function(a){this.opacity=1;this.shading=THREE.FlatShading;this.blending=THREE.NormalBlending;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.MeshNormalMaterial"}};THREE.MeshFaceMaterial=function(){this.toString=function(){return"THREE.MeshFaceMaterial"}};
THREE.MeshCubeMaterial=function(a){this.id=THREE.MeshCubeMaterial.value++;this.env_map=null;this.blending=THREE.NormalBlending;if(a)if(a.env_map!==undefined)this.env_map=a.env_map;this.toString=function(){return"THREE.MeshCubeMaterial( id: "+this.id+"<br/>env_map: "+this.env_map+" )"}};THREE.MeshCubeMaterialCounter={value:0};
THREE.MeshShaderMaterial=function(a){this.id=THREE.MeshShaderMaterialCounter.value++;this.vertex_shader=this.fragment_shader="void main() {}";this.uniforms={};this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){if(a.fragment_shader!==undefined)this.fragment_shader=a.fragment_shader;if(a.vertex_shader!==undefined)this.vertex_shader=a.vertex_shader;if(a.uniforms!==
undefined)this.uniforms=a.uniforms;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin}this.toString=function(){return"THREE.MeshShaderMaterial (<br/>id: "+this.id+
"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>)"}};THREE.MeshShaderMaterialCounter={value:0};
THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.offset=new THREE.Vector2;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+
this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
THREE.Texture=function(a,b,d,e,f,k){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=e!==undefined?e:THREE.ClampToEdgeWrapping;this.mag_filter=f!==undefined?f:THREE.LinearFilter;this.min_filter=k!==undefined?k:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
this.min_filter+"<br/>)"}};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.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
A
alteredq 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
THREE.Projector=function(){function a(y,o){var i=0,p=1,h=y.z+y.w,w=o.z+o.w,m=-y.z+y.w,n=-o.z+o.w;if(h>=0&&w>=0&&m>=0&&n>=0)return true;else if(h<0&&w<0||m<0&&n<0)return false;else{if(h<0)i=Math.max(i,h/(h-w));else if(w<0)p=Math.min(p,h/(h-w));if(m<0)i=Math.max(i,m/(m-n));else if(n<0)p=Math.min(p,m/(m-n));if(p<i)return false;else{y.lerpSelf(o,i);o.lerpSelf(y,1-p);return true}}}var b=null,d,e,f,k=[],l,g,j=[],c,t,x=[],q=new THREE.Vector4,s=new THREE.Matrix4,v=new THREE.Matrix4,z=new THREE.Vector4,K=
new THREE.Vector4,F;this.projectScene=function(y,o){var i,p,h,w,m,n,D,A,L,E,O,S,G,T,N,U,V;b=[];f=g=t=0;o.autoUpdateMatrix&&o.updateMatrix();s.multiply(o.projectionMatrix,o.matrix);D=y.objects;i=0;for(p=D.length;i<p;i++){A=D[i];A.autoUpdateMatrix&&A.updateMatrix();L=A.matrix;E=A.rotationMatrix;O=A.material;S=A.overdraw;if(A instanceof THREE.Mesh){G=A.geometry.vertices;h=0;for(w=G.length;h<w;h++){T=G[h];T.positionWorld.copy(T.position);L.multiplyVector3(T.positionWorld);N=T.positionScreen;N.copy(T.positionWorld);
s.multiplyVector4(N);N.multiplyScalar(1/N.w);T.__visible=N.z>0&&N.z<1}T=A.geometry.faces;h=0;for(w=T.length;h<w;h++){N=T[h];if(N instanceof THREE.Face3){m=G[N.a];n=G[N.b];U=G[N.c];if(m.__visible&&n.__visible&&U.__visible)if(A.doubleSided||A.flipSided!=(U.positionScreen.x-m.positionScreen.x)*(n.positionScreen.y-m.positionScreen.y)-(U.positionScreen.y-m.positionScreen.y)*(n.positionScreen.x-m.positionScreen.x)<0){d=k[f]=k[f]||new THREE.RenderableFace3;d.v1.positionWorld.copy(m.positionWorld);d.v2.positionWorld.copy(n.positionWorld);
d.v3.positionWorld.copy(U.positionWorld);d.v1.positionScreen.copy(m.positionScreen);d.v2.positionScreen.copy(n.positionScreen);d.v3.positionScreen.copy(U.positionScreen);d.normalWorld.copy(N.normal);E.multiplyVector3(d.normalWorld);d.centroidWorld.copy(N.centroid);L.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);s.multiplyVector3(d.centroidScreen);U=N.vertexNormals;F=d.vertexNormalsWorld;m=0;for(n=U.length;m<n;m++){V=F[m]=F[m]||new THREE.Vector3;V.copy(U[m]);E.multiplyVector3(V)}d.z=
d.centroidScreen.z;d.meshMaterial=O;d.faceMaterial=N.material;d.overdraw=S;if(A.geometry.uvs[h]){d.uvs[0]=A.geometry.uvs[h][0];d.uvs[1]=A.geometry.uvs[h][1];d.uvs[2]=A.geometry.uvs[h][2]}b.push(d);f++}}else if(N instanceof THREE.Face4){m=G[N.a];n=G[N.b];U=G[N.c];V=G[N.d];if(m.__visible&&n.__visible&&U.__visible&&V.__visible)if(A.doubleSided||A.flipSided!=((V.positionScreen.x-m.positionScreen.x)*(n.positionScreen.y-m.positionScreen.y)-(V.positionScreen.y-m.positionScreen.y)*(n.positionScreen.x-m.positionScreen.x)<
0||(n.positionScreen.x-U.positionScreen.x)*(V.positionScreen.y-U.positionScreen.y)-(n.positionScreen.y-U.positionScreen.y)*(V.positionScreen.x-U.positionScreen.x)<0)){d=k[f]=k[f]||new THREE.RenderableFace3;d.v1.positionWorld.copy(m.positionWorld);d.v2.positionWorld.copy(n.positionWorld);d.v3.positionWorld.copy(V.positionWorld);d.v1.positionScreen.copy(m.positionScreen);d.v2.positionScreen.copy(n.positionScreen);d.v3.positionScreen.copy(V.positionScreen);d.normalWorld.copy(N.normal);E.multiplyVector3(d.normalWorld);
d.centroidWorld.copy(N.centroid);L.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);s.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=O;d.faceMaterial=N.material;d.overdraw=S;if(A.geometry.uvs[h]){d.uvs[0]=A.geometry.uvs[h][0];d.uvs[1]=A.geometry.uvs[h][1];d.uvs[2]=A.geometry.uvs[h][3]}b.push(d);f++;e=k[f]=k[f]||new THREE.RenderableFace3;e.v1.positionWorld.copy(n.positionWorld);e.v2.positionWorld.copy(U.positionWorld);e.v3.positionWorld.copy(V.positionWorld);
e.v1.positionScreen.copy(n.positionScreen);e.v2.positionScreen.copy(U.positionScreen);e.v3.positionScreen.copy(V.positionScreen);e.normalWorld.copy(d.normalWorld);e.centroidWorld.copy(d.centroidWorld);e.centroidScreen.copy(d.centroidScreen);e.z=e.centroidScreen.z;e.meshMaterial=O;e.faceMaterial=N.material;e.overdraw=S;if(A.geometry.uvs[h]){e.uvs[0]=A.geometry.uvs[h][1];e.uvs[1]=A.geometry.uvs[h][2];e.uvs[2]=A.geometry.uvs[h][3]}b.push(e);f++}}}}else if(A instanceof THREE.Line){v.multiply(s,L);G=A.geometry.vertices;
T=G[0];T.positionScreen.copy(T.position);v.multiplyVector4(T.positionScreen);h=1;for(w=G.length;h<w;h++){m=G[h];m.positionScreen.copy(m.position);v.multiplyVector4(m.positionScreen);n=G[h-1];z.copy(m.positionScreen);K.copy(n.positionScreen);if(a(z,K)){z.multiplyScalar(1/z.w);K.multiplyScalar(1/K.w);l=j[g]=j[g]||new THREE.RenderableLine;l.v1.positionScreen.copy(z);l.v2.positionScreen.copy(K);l.z=Math.max(z.z,K.z);l.material=A.material;b.push(l);g++}}}else if(A instanceof THREE.Particle){q.set(A.position.x,
A.position.y,A.position.z,1);s.multiplyVector4(q);q.z/=q.w;if(q.z>0&&q.z<1){c=x[t]=x[t]||new THREE.RenderableParticle;c.x=q.x/q.w;c.y=q.y/q.w;c.z=q.z;c.rotation=A.rotation.z;c.scale.x=A.scale.x*Math.abs(c.x-(q.x+o.projectionMatrix.n11)/(q.w+o.projectionMatrix.n14));c.scale.y=A.scale.y*Math.abs(c.y-(q.y+o.projectionMatrix.n22)/(q.w+o.projectionMatrix.n24));c.material=A.material;b.push(c);t++}}}b.sort(function(Q,H){return H.z-Q.z});return b};this.unprojectVector=function(y,o){var i=new THREE.Matrix4;
i.multiply(THREE.Matrix4.makeInvert(o.matrix),THREE.Matrix4.makeInvert(o.projectionMatrix));i.multiplyVector3(y);return y}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,e,f,k;this.domElement=document.createElement("div");this.setSize=function(l,g){d=l;e=g;f=d/2;k=e/2};this.render=function(l,g){var j,c,t,x,q,s,v,z;a=b.projectScene(l,g);j=0;for(c=a.length;j<c;j++){q=a[j];if(q instanceof THREE.RenderableParticle){v=q.x*f+f;z=q.y*k+k;t=0;for(x=q.material.length;t<x;t++){s=q.material[t];if(s instanceof THREE.ParticleDOMMaterial){s=s.domElement;s.style.left=v+"px";s.style.top=z+"px"}}}}}};
THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),e,f,k,l,g=d.getContext("2d"),j=1,c=0,t=null,x=null,q=1,s,v,z,K,F,y,o,i,p,h=new THREE.Color,w=new THREE.Color,m=new THREE.Color,n=new THREE.Color,D=new THREE.Color,A,L,E,O,S,G,T,N,U,V,Q=new THREE.Rectangle,H=new THREE.Rectangle,J=new THREE.Rectangle,$=false,r=new THREE.Color,u=new THREE.Color,B=new THREE.Color,M=new THREE.Color,X=Math.PI*2,Y=new THREE.Vector3,ea,ma,oa,fa,ra,va,pa=16;ea=document.createElement("canvas");
ea.width=ea.height=2;ma=ea.getContext("2d");ma.fillStyle="rgba(0,0,0,1)";ma.fillRect(0,0,2,2);oa=ma.getImageData(0,0,2,2);fa=oa.data;ra=document.createElement("canvas");ra.width=ra.height=pa;va=ra.getContext("2d");va.translate(-pa/2,-pa/2);va.scale(pa,pa);pa--;this.domElement=d;this.autoClear=true;this.setSize=function(ia,wa){e=ia;f=wa;k=e/2;l=f/2;d.width=e;d.height=f;Q.set(-k,-l,k,l)};this.clear=function(){if(!H.isEmpty()){H.inflate(1);H.minSelf(Q);g.clearRect(H.getX(),H.getY(),H.getWidth(),H.getHeight());
H.empty()}};this.render=function(ia,wa){function Ka(C){var W,R,I,P=C.lights;u.setRGB(0,0,0);B.setRGB(0,0,0);M.setRGB(0,0,0);C=0;for(W=P.length;C<W;C++){R=P[C];I=R.color;if(R instanceof THREE.AmbientLight){u.r+=I.r;u.g+=I.g;u.b+=I.b}else if(R instanceof THREE.DirectionalLight){B.r+=I.r;B.g+=I.g;B.b+=I.b}else if(R instanceof THREE.PointLight){M.r+=I.r;M.g+=I.g;M.b+=I.b}}}function xa(C,W,R,I){var P,Z,ba,ca,da=C.lights;C=0;for(P=da.length;C<P;C++){Z=da[C];ba=Z.color;ca=Z.intensity;if(Z instanceof THREE.DirectionalLight){Z=
R.dot(Z.position)*ca;if(Z>0){I.r+=ba.r*Z;I.g+=ba.g*Z;I.b+=ba.b*Z}}else if(Z instanceof THREE.PointLight){Y.sub(Z.position,W);Y.normalize();Z=R.dot(Y)*ca;if(Z>0){I.r+=ba.r*Z;I.g+=ba.g*Z;I.b+=ba.b*Z}}}}function La(C,W,R){if(R.opacity!=0){Ca(R.opacity);ya(R.blending);var I,P,Z,ba,ca,da;if(R instanceof THREE.ParticleBasicMaterial){if(R.map){ba=R.map;ca=ba.width>>1;da=ba.height>>1;P=W.scale.x*k;Z=W.scale.y*l;R=P*ca;I=Z*da;J.set(C.x-R,C.y-I,C.x+R,C.y+I);if(Q.instersects(J)){g.save();g.translate(C.x,C.y);
g.rotate(-W.rotation);g.scale(P,-Z);g.translate(-ca,-da);g.drawImage(ba,0,0);g.restore()}}}else if(R instanceof THREE.ParticleCircleMaterial){if($){r.r=u.r+B.r+M.r;r.g=u.g+B.g+M.g;r.b=u.b+B.b+M.b;h.r=R.color.r*r.r;h.g=R.color.g*r.g;h.b=R.color.b*r.b;h.updateStyleString()}else h.__styleString=R.color.__styleString;R=W.scale.x*k;I=W.scale.y*l;J.set(C.x-R,C.y-I,C.x+R,C.y+I);if(Q.instersects(J)){P=h.__styleString;if(x!=P)g.fillStyle=x=P;g.save();g.translate(C.x,C.y);g.rotate(-W.rotation);g.scale(R,I);
g.beginPath();g.arc(0,0,1,0,X,true);g.closePath();g.fill();g.restore()}}}}function Ma(C,W,R,I){if(I.opacity!=0){Ca(I.opacity);ya(I.blending);g.beginPath();g.moveTo(C.positionScreen.x,C.positionScreen.y);g.lineTo(W.positionScreen.x,W.positionScreen.y);g.closePath();if(I instanceof THREE.LineBasicMaterial){h.__styleString=I.color.__styleString;C=I.linewidth;if(q!=C)g.lineWidth=q=C;C=h.__styleString;if(t!=C)g.strokeStyle=t=C;g.stroke();J.inflate(I.linewidth*2)}}}function Ga(C,W,R,I,P,Z){if(P.opacity!=
0){Ca(P.opacity);ya(P.blending);K=C.positionScreen.x;F=C.positionScreen.y;y=W.positionScreen.x;o=W.positionScreen.y;i=R.positionScreen.x;p=R.positionScreen.y;g.beginPath();g.moveTo(K,F);g.lineTo(y,o);g.lineTo(i,p);g.lineTo(K,F);g.closePath();if(P instanceof THREE.MeshBasicMaterial)if(P.map)P.map.image.loaded&&P.map.mapping instanceof THREE.UVMapping&&sa(K,F,y,o,i,p,P.map.image,I.uvs[0].u,I.uvs[0].v,I.uvs[1].u,I.uvs[1].v,I.uvs[2].u,I.uvs[2].v);else if(P.env_map){if(P.env_map.image.loaded)if(P.env_map.mapping instanceof
THREE.SphericalReflectionMapping){C=wa.matrix;Y.copy(I.vertexNormalsWorld[0]);S=(Y.x*C.n11+Y.y*C.n12+Y.z*C.n13)*0.5+0.5;G=-(Y.x*C.n21+Y.y*C.n22+Y.z*C.n23)*0.5+0.5;Y.copy(I.vertexNormalsWorld[1]);T=(Y.x*C.n11+Y.y*C.n12+Y.z*C.n13)*0.5+0.5;N=-(Y.x*C.n21+Y.y*C.n22+Y.z*C.n23)*0.5+0.5;Y.copy(I.vertexNormalsWorld[2]);U=(Y.x*C.n11+Y.y*C.n12+Y.z*C.n13)*0.5+0.5;V=-(Y.x*C.n21+Y.y*C.n22+Y.z*C.n23)*0.5+0.5;sa(K,F,y,o,i,p,P.env_map.image,S,G,T,N,U,V)}}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth):
Aa(P.color.__styleString);else if(P instanceof THREE.MeshLambertMaterial){if(P.map&&!P.wireframe){P.map.mapping instanceof THREE.UVMapping&&sa(K,F,y,o,i,p,P.map.image,I.uvs[0].u,I.uvs[0].v,I.uvs[1].u,I.uvs[1].v,I.uvs[2].u,I.uvs[2].v);ya(THREE.SubtractiveBlending)}if($)if(!P.wireframe&&P.shading==THREE.SmoothShading&&I.vertexNormalsWorld.length==3){w.r=m.r=n.r=u.r;w.g=m.g=n.g=u.g;w.b=m.b=n.b=u.b;xa(Z,I.v1.positionWorld,I.vertexNormalsWorld[0],w);xa(Z,I.v2.positionWorld,I.vertexNormalsWorld[1],m);xa(Z,
I.v3.positionWorld,I.vertexNormalsWorld[2],n);D.r=(m.r+n.r)*0.5;D.g=(m.g+n.g)*0.5;D.b=(m.b+n.b)*0.5;O=Ha(w,m,n,D);sa(K,F,y,o,i,p,O,0,0,1,0,0,1)}else{r.r=u.r;r.g=u.g;r.b=u.b;xa(Z,I.centroidWorld,I.normalWorld,r);h.r=P.color.r*r.r;h.g=P.color.g*r.g;h.b=P.color.b*r.b;h.updateStyleString();P.wireframe?za(h.__styleString,P.wireframe_linewidth):Aa(h.__styleString)}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth):Aa(P.color.__styleString)}else if(P instanceof THREE.MeshDepthMaterial){A=P.__2near;
L=P.__farPlusNear;E=P.__farMinusNear;w.r=w.g=w.b=1-A/(L-C.positionScreen.z*E);m.r=m.g=m.b=1-A/(L-W.positionScreen.z*E);n.r=n.g=n.b=1-A/(L-R.positionScreen.z*E);D.r=(m.r+n.r)*0.5;D.g=(m.g+n.g)*0.5;D.b=(m.b+n.b)*0.5;O=Ha(w,m,n,D);sa(K,F,y,o,i,p,O,0,0,1,0,0,1)}else if(P instanceof THREE.MeshNormalMaterial){h.r=Da(I.normalWorld.x);h.g=Da(I.normalWorld.y);h.b=Da(I.normalWorld.z);h.updateStyleString();P.wireframe?za(h.__styleString,P.wireframe_linewidth):Aa(h.__styleString)}}}function za(C,W){if(t!=C)g.strokeStyle=
t=C;if(q!=W)g.lineWidth=q=W;g.stroke();J.inflate(W*2)}function Aa(C){if(x!=C)g.fillStyle=x=C;g.fill()}function sa(C,W,R,I,P,Z,ba,ca,da,ja,ga,ka,ta){var na,la;na=ba.width-1;la=ba.height-1;ca*=na;da*=la;ja*=na;ga*=la;ka*=na;ta*=la;R-=C;I-=W;P-=C;Z-=W;ja-=ca;ga-=da;ka-=ca;ta-=da;la=1/(ja*ta-ka*ga);na=(ta*R-ga*P)*la;ga=(ta*I-ga*Z)*la;R=(ja*P-ka*R)*la;I=(ja*Z-ka*I)*la;C=C-na*ca-R*da;W=W-ga*ca-I*da;g.save();g.transform(na,ga,R,I,C,W);g.clip();g.drawImage(ba,0,0);g.restore()}function Ca(C){if(j!=C)g.globalAlpha=
j=C}function ya(C){if(c!=C){switch(C){case THREE.NormalBlending:g.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:g.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:g.globalCompositeOperation="darker"}c=C}}function Ha(C,W,R,I){var P=~~(C.r*255),Z=~~(C.g*255);C=~~(C.b*255);var ba=~~(W.r*255),ca=~~(W.g*255);W=~~(W.b*255);var da=~~(R.r*255),ja=~~(R.g*255);R=~~(R.b*255);var ga=~~(I.r*255),ka=~~(I.g*255);I=~~(I.b*255);fa[0]=P<0?0:P>255?255:P;fa[1]=Z<0?0:
Z>255?255:Z;fa[2]=C<0?0:C>255?255:C;fa[4]=ba<0?0:ba>255?255:ba;fa[5]=ca<0?0:ca>255?255:ca;fa[6]=W<0?0:W>255?255:W;fa[8]=da<0?0:da>255?255:da;fa[9]=ja<0?0:ja>255?255:ja;fa[10]=R<0?0:R>255?255:R;fa[12]=ga<0?0:ga>255?255:ga;fa[13]=ka<0?0:ka>255?255:ka;fa[14]=I<0?0:I>255?255:I;ma.putImageData(oa,0,0);va.drawImage(ea,0,0);return ra}function Da(C){C=(C+1)*0.5;return C<0?0:C>1?1:C}function Ea(C,W){var R=W.x-C.x,I=W.y-C.y,P=1/Math.sqrt(R*R+I*I);R*=P;I*=P;W.x+=R;W.y+=I;C.x-=R;C.y-=I}var Ba,Ia,aa,ha,qa,Fa,
Ja,ua;g.setTransform(1,0,0,-1,k,l);this.autoClear&&this.clear();a=b.projectScene(ia,wa);($=ia.lights.length>0)&&Ka(ia);Ba=0;for(Ia=a.length;Ba<Ia;Ba++){aa=a[Ba];J.empty();if(aa instanceof THREE.RenderableParticle){s=aa;s.x*=k;s.y*=l;ha=0;for(qa=aa.material.length;ha<qa;ha++)La(s,aa,aa.material[ha],ia)}else if(aa instanceof THREE.RenderableLine){s=aa.v1;v=aa.v2;s.positionScreen.x*=k;s.positionScreen.y*=l;v.positionScreen.x*=k;v.positionScreen.y*=l;J.addPoint(s.positionScreen.x,s.positionScreen.y);
J.addPoint(v.positionScreen.x,v.positionScreen.y);if(Q.instersects(J)){ha=0;for(qa=aa.material.length;ha<qa;)Ma(s,v,aa,aa.material[ha++],ia)}}else if(aa instanceof THREE.RenderableFace3){s=aa.v1;v=aa.v2;z=aa.v3;s.positionScreen.x*=k;s.positionScreen.y*=l;v.positionScreen.x*=k;v.positionScreen.y*=l;z.positionScreen.x*=k;z.positionScreen.y*=l;if(aa.overdraw){Ea(s.positionScreen,v.positionScreen);Ea(v.positionScreen,z.positionScreen);Ea(z.positionScreen,s.positionScreen)}J.add3Points(s.positionScreen.x,
s.positionScreen.y,v.positionScreen.x,v.positionScreen.y,z.positionScreen.x,z.positionScreen.y);if(Q.instersects(J)){ha=0;for(qa=aa.meshMaterial.length;ha<qa;){ua=aa.meshMaterial[ha++];if(ua instanceof THREE.MeshFaceMaterial){Fa=0;for(Ja=aa.faceMaterial.length;Fa<Ja;)(ua=aa.faceMaterial[Fa++])&&Ga(s,v,z,aa,ua,ia)}else Ga(s,v,z,aa,ua,ia)}}}H.addRectangle(J)}g.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(N,U,V){var Q,H,J,$;Q=0;for(H=N.lights.length;Q<H;Q++){J=N.lights[Q];if(J instanceof THREE.DirectionalLight){$=U.normalWorld.dot(J.position)*J.intensity;if($>0){V.r+=J.color.r*$;V.g+=J.color.g*$;V.b+=J.color.b*$}}else if(J instanceof THREE.PointLight){n.sub(J.position,U.centroidWorld);n.normalize();$=U.normalWorld.dot(n)*J.intensity;if($>0){V.r+=J.color.r*$;V.g+=J.color.g*$;V.b+=J.color.b*$}}}}function b(N,U,V,Q,H,J){E=e(O++);E.setAttribute("d","M "+N.positionScreen.x+
" "+N.positionScreen.y+" L "+U.positionScreen.x+" "+U.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(H instanceof THREE.MeshBasicMaterial)o.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshLambertMaterial)if(y){i.r=p.r;i.g=p.g;i.b=p.b;a(J,Q,i);o.r=H.color.r*i.r;o.g=H.color.g*i.g;o.b=H.color.b*i.b;o.updateStyleString()}else o.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshDepthMaterial){m=1-H.__2near/(H.__farPlusNear-Q.z*H.__farMinusNear);
o.setRGB(m,m,m)}else H instanceof THREE.MeshNormalMaterial&&o.setRGB(f(Q.normalWorld.x),f(Q.normalWorld.y),f(Q.normalWorld.z));H.wireframe?E.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+H.wireframe_linewidth+"; stroke-opacity: "+H.opacity+"; stroke-linecap: "+H.wireframe_linecap+"; stroke-linejoin: "+H.wireframe_linejoin):E.setAttribute("style","fill: "+o.__styleString+"; fill-opacity: "+H.opacity);g.appendChild(E)}function d(N,U,V,Q,H,J,$){E=e(O++);E.setAttribute("d",
"M "+N.positionScreen.x+" "+N.positionScreen.y+" L "+U.positionScreen.x+" "+U.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)o.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(y){i.r=p.r;i.g=p.g;i.b=p.b;a($,H,i);o.r=J.color.r*i.r;o.g=J.color.g*i.g;o.b=J.color.b*i.b;o.updateStyleString()}else o.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){m=
1-J.__2near/(J.__farPlusNear-H.z*J.__farMinusNear);o.setRGB(m,m,m)}else J instanceof THREE.MeshNormalMaterial&&o.setRGB(f(H.normalWorld.x),f(H.normalWorld.y),f(H.normalWorld.z));J.wireframe?E.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):E.setAttribute("style","fill: "+o.__styleString+"; fill-opacity: "+J.opacity);g.appendChild(E)}
function e(N){if(D[N]==null){D[N]=document.createElementNS("http://www.w3.org/2000/svg","path");T==0&&D[N].setAttribute("shape-rendering","crispEdges");return D[N]}return D[N]}function f(N){return N<0?Math.min((1+N)*0.5,0.5):0.5+Math.min(N*0.5,0.5)}var k=null,l=new THREE.Projector,g=document.createElementNS("http://www.w3.org/2000/svg","svg"),j,c,t,x,q,s,v,z,K=new THREE.Rectangle,F=new THREE.Rectangle,y=false,o=new THREE.Color(16777215),i=new THREE.Color(16777215),p=new THREE.Color(0),h=new THREE.Color(0),
w=new THREE.Color(0),m,n=new THREE.Vector3,D=[],A=[],L=[],E,O,S,G,T=1;this.domElement=g;this.autoClear=true;this.setQuality=function(N){switch(N){case "high":T=1;break;case "low":T=0}};this.setSize=function(N,U){j=N;c=U;t=j/2;x=c/2;g.setAttribute("viewBox",-t+" "+-x+" "+j+" "+c);g.setAttribute("width",j);g.setAttribute("height",c);K.set(-t,-x,t,x)};this.clear=function(){for(;g.childNodes.length>0;)g.removeChild(g.childNodes[0])};this.render=function(N,U){var V,Q,H,J,$,r,u,B;this.autoClear&&this.clear();
k=l.projectScene(N,U);G=S=O=0;if(y=N.lights.length>0){u=N.lights;p.setRGB(0,0,0);h.setRGB(0,0,0);w.setRGB(0,0,0);V=0;for(Q=u.length;V<Q;V++){H=u[V];J=H.color;if(H instanceof THREE.AmbientLight){p.r+=J.r;p.g+=J.g;p.b+=J.b}else if(H instanceof THREE.DirectionalLight){h.r+=J.r;h.g+=J.g;h.b+=J.b}else if(H instanceof THREE.PointLight){w.r+=J.r;w.g+=J.g;w.b+=J.b}}}V=0;for(Q=k.length;V<Q;V++){u=k[V];F.empty();if(u instanceof THREE.RenderableParticle){q=u;q.x*=t;q.y*=-x;H=0;for(J=u.material.length;H<J;H++)if(B=
u.material[H]){$=q;r=u;B=B;var M=S++;if(A[M]==null){A[M]=document.createElementNS("http://www.w3.org/2000/svg","circle");T==0&&A[M].setAttribute("shape-rendering","crispEdges")}E=A[M];E.setAttribute("cx",$.x);E.setAttribute("cy",$.y);E.setAttribute("r",r.scale.x*t);if(B instanceof THREE.ParticleCircleMaterial){if(y){i.r=p.r+h.r+w.r;i.g=p.g+h.g+w.g;i.b=p.b+h.b+w.b;o.r=B.color.r*i.r;o.g=B.color.g*i.g;o.b=B.color.b*i.b;o.updateStyleString()}else o=B.color;E.setAttribute("style","fill: "+o.__styleString)}g.appendChild(E)}}else if(u instanceof
THREE.RenderableLine){q=u.v1;s=u.v2;q.positionScreen.x*=t;q.positionScreen.y*=-x;s.positionScreen.x*=t;s.positionScreen.y*=-x;F.addPoint(q.positionScreen.x,q.positionScreen.y);F.addPoint(s.positionScreen.x,s.positionScreen.y);if(K.instersects(F)){H=0;for(J=u.material.length;H<J;)if(B=u.material[H++]){$=q;r=s;B=B;M=G++;if(L[M]==null){L[M]=document.createElementNS("http://www.w3.org/2000/svg","line");T==0&&L[M].setAttribute("shape-rendering","crispEdges")}E=L[M];E.setAttribute("x1",$.positionScreen.x);
E.setAttribute("y1",$.positionScreen.y);E.setAttribute("x2",r.positionScreen.x);E.setAttribute("y2",r.positionScreen.y);if(B instanceof THREE.LineBasicMaterial){o.__styleString=B.color.__styleString;E.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+B.linewidth+"; stroke-opacity: "+B.opacity+"; stroke-linecap: "+B.linecap+"; stroke-linejoin: "+B.linejoin);g.appendChild(E)}}}}else if(u instanceof THREE.RenderableFace3){q=u.v1;s=u.v2;v=u.v3;q.positionScreen.x*=t;q.positionScreen.y*=
-x;s.positionScreen.x*=t;s.positionScreen.y*=-x;v.positionScreen.x*=t;v.positionScreen.y*=-x;F.addPoint(q.positionScreen.x,q.positionScreen.y);F.addPoint(s.positionScreen.x,s.positionScreen.y);F.addPoint(v.positionScreen.x,v.positionScreen.y);if(K.instersects(F)){H=0;for(J=u.meshMaterial.length;H<J;){B=u.meshMaterial[H++];if(B instanceof THREE.MeshFaceMaterial){$=0;for(r=u.faceMaterial.length;$<r;)(B=u.faceMaterial[$++])&&b(q,s,v,u,B,N)}else B&&b(q,s,v,u,B,N)}}}else if(u instanceof THREE.RenderableFace4){q=
u.v1;s=u.v2;v=u.v3;z=u.v4;q.positionScreen.x*=t;q.positionScreen.y*=-x;s.positionScreen.x*=t;s.positionScreen.y*=-x;v.positionScreen.x*=t;v.positionScreen.y*=-x;z.positionScreen.x*=t;z.positionScreen.y*=-x;F.addPoint(q.positionScreen.x,q.positionScreen.y);F.addPoint(s.positionScreen.x,s.positionScreen.y);F.addPoint(v.positionScreen.x,v.positionScreen.y);F.addPoint(z.positionScreen.x,z.positionScreen.y);if(K.instersects(F)){H=0;for(J=u.meshMaterial.length;H<J;){B=u.meshMaterial[H++];if(B instanceof
THREE.MeshFaceMaterial){$=0;for(r=u.faceMaterial.length;$<r;)(B=u.faceMaterial[$++])&&d(q,s,v,z,u,B,N)}else B&&d(q,s,v,z,u,B,N)}}}}}};
THREE.WebGLRenderer=function(a){function b(i,p){var h=c.createProgram(),w=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(h,l("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+
i));c.attachShader(h,l("vertex",w+p));c.linkProgram(h);c.getProgramParameter(h,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(h,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");h.uniforms={};h.attributes={};return h}function d(i,p){if(i.image.length==6){if(!i.image.__webGLTextureCube&&!i.image.__cubeMapInitialized&&i.image.loadCount==6){i.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,i.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,
c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var h=0;h<6;++h)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+h,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,i.image[h]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);i.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+p);c.bindTexture(c.TEXTURE_CUBE_MAP,
i.image.__webGLTextureCube)}}function e(i,p){if(!i.__webGLTexture&&i.image.loaded){i.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,i.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,i.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,g(i.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,g(i.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,g(i.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,g(i.min_filter));c.generateMipmap(c.TEXTURE_2D);
c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+p);c.bindTexture(c.TEXTURE_2D,i.__webGLTexture)}function f(i,p){var h,w,m;h=0;for(w=p.length;h<w;h++){m=p[h];i.uniforms[m]=c.getUniformLocation(i,m)}}function k(i,p){var h,w,m;h=0;for(w=p.length;h<w;h++){m=p[h];i.attributes[m]=c.getAttribLocation(i,m);i.attributes[m]>=0&&c.enableVertexAttribArray(i.attributes[m])}}function l(i,p){var h;if(i=="fragment")h=c.createShader(c.FRAGMENT_SHADER);else if(i=="vertex")h=c.createShader(c.VERTEX_SHADER);
c.shaderSource(h,p);c.compileShader(h);if(!c.getShaderParameter(h,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(h));return null}return h}function g(i){switch(i){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;
case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var j=document.createElement("canvas"),c,t,x,q=new THREE.Matrix4,s,v=new Float32Array(16),z=new Float32Array(16),K=new Float32Array(16),F=new Float32Array(9),y=new Float32Array(16);a=function(i,p){if(i){var h,w,m,n=pointLights=maxDirLights=maxPointLights=0;h=0;for(w=i.lights.length;h<w;h++){m=i.lights[h];m instanceof THREE.DirectionalLight&&n++;m instanceof
THREE.PointLight&&pointLights++}if(pointLights+n<=p){maxDirLights=n;maxPointLights=pointLights}else{maxDirLights=Math.ceil(p*n/(pointLights+n));maxPointLights=p-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:p-1}}(a,4);this.domElement=j;this.autoClear=true;try{c=j.getContext("experimental-webgl",{antialias:true})}catch(o){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);
c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);t=x=function(i,p){var h=[i?"#define MAX_DIR_LIGHTS "+i:"",p?"#define MAX_POINT_LIGHTS "+p:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",i?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",i?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":
A
alteredq 已提交
145
"",p?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",p?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",p?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
A
alteredq 已提交
146
i?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",i?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",i?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",i?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",i?"}":"",p?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",p?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",p?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
A
alteredq 已提交
147
"",p?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",p?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",p?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
A
alteredq 已提交
148 149
w=[i?"#define MAX_DIR_LIGHTS "+i:"",p?"#define MAX_POINT_LIGHTS "+p:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
i?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",p?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
A
alteredq 已提交
150
p?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",p?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",p?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",p?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",p?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",p?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",p?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",p?"float pointSpecularWeight = 0.0;":"",p?"if ( pointDotNormalHalf >= 0.0 )":
A
alteredq 已提交
151 152
"",p?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",p?"pointDiffuse  += mColor * pointDiffuseWeight;":"",p?"pointSpecular += mSpecular * pointSpecularWeight;":"",p?"}":"",i?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",i?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",i?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",i?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",i?"vec3 dirVector = normalize( lDirection.xyz );":"",i?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
"",i?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",i?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",i?"float dirSpecularWeight = 0.0;":"",i?"if ( dirDotNormalHalf >= 0.0 )":"",i?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",i?"dirDiffuse  += mColor * dirDiffuseWeight;":"",i?"dirSpecular += mSpecular * dirSpecularWeight;":"",i?"}":"","vec4 totalLight = mAmbient;",i?"totalLight += dirDiffuse + dirSpecular;":"",p?"totalLight += pointDiffuse + pointSpecular;":
A
alteredq 已提交
153
"","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
A
alteredq 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
h=b(w,h);c.useProgram(h);f(h,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);i&&f(h,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);p&&f(h,["pointLightNumber","pointLightColor",
"pointLightPosition"]);c.uniform1i(h.uniforms.enableMap,0);c.uniform1i(h.uniforms.tMap,0);c.uniform1i(h.uniforms.enableCubeMap,0);c.uniform1i(h.uniforms.tCube,1);c.uniform1i(h.uniforms.mixEnvMap,0);c.uniform1i(h.uniforms.useRefract,0);k(h,["position","normal","uv"]);return h}(a.directional,a.point);this.setSize=function(i,p){j.width=i;j.height=p;c.viewport(0,0,j.width,j.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(i,p){var h,w,m,n,D,A=[],
L=[],E=[];n=[];D=[];c.uniform1i(i.uniforms.enableLighting,p.length);h=0;for(w=p.length;h<w;h++){m=p[h];if(m instanceof THREE.AmbientLight)A.push(m);else if(m instanceof THREE.DirectionalLight)E.push(m);else m instanceof THREE.PointLight&&L.push(m)}h=m=n=D=0;for(w=A.length;h<w;h++){m+=A[h].color.r;n+=A[h].color.g;D+=A[h].color.b}c.uniform3f(i.uniforms.ambientLightColor,m,n,D);n=[];D=[];h=0;for(w=E.length;h<w;h++){m=E[h];n.push(m.color.r*m.intensity);n.push(m.color.g*m.intensity);n.push(m.color.b*m.intensity);
D.push(m.position.x);D.push(m.position.y);D.push(m.position.z)}if(E.length){c.uniform1i(i.uniforms.directionalLightNumber,E.length);c.uniform3fv(i.uniforms.directionalLightDirection,D);c.uniform3fv(i.uniforms.directionalLightColor,n)}n=[];D=[];h=0;for(w=L.length;h<w;h++){m=L[h];n.push(m.color.r*m.intensity);n.push(m.color.g*m.intensity);n.push(m.color.b*m.intensity);D.push(m.position.x);D.push(m.position.y);D.push(m.position.z)}if(L.length){c.uniform1i(i.uniforms.pointLightNumber,L.length);c.uniform3fv(i.uniforms.pointLightPosition,
D);c.uniform3fv(i.uniforms.pointLightColor,n)}};this.createBuffers=function(i,p){var h,w,m,n,D,A,L,E,O,S=[],G=[],T=[],N=[],U=[],V=[],Q=0,H=i.geometry.geometryChunks[p],J;m=false;h=0;for(w=i.material.length;h<w;h++){meshMaterial=i.material[h];if(meshMaterial instanceof THREE.MeshFaceMaterial){D=0;for(J=H.material.length;D<J;D++)if(H.material[D]&&H.material[D].shading!=undefined&&H.material[D].shading==THREE.SmoothShading){m=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
THREE.SmoothShading){m=true;break}if(m)break}J=m;h=0;for(w=H.faces.length;h<w;h++){m=H.faces[h];n=i.geometry.faces[m];D=n.vertexNormals;faceNormal=n.normal;m=i.geometry.uvs[m];if(n instanceof THREE.Face3){A=i.geometry.vertices[n.a].position;L=i.geometry.vertices[n.b].position;E=i.geometry.vertices[n.c].position;T.push(A.x,A.y,A.z);T.push(L.x,L.y,L.z);T.push(E.x,E.y,E.z);if(i.geometry.hasTangents){A=i.geometry.vertices[n.a].tangent;L=i.geometry.vertices[n.b].tangent;E=i.geometry.vertices[n.c].tangent;
U.push(A.x,A.y,A.z,A.w);U.push(L.x,L.y,L.z,L.w);U.push(E.x,E.y,E.z,E.w)}if(D.length==3&&J)for(n=0;n<3;n++)N.push(D[n].x,D[n].y,D[n].z);else for(n=0;n<3;n++)N.push(faceNormal.x,faceNormal.y,faceNormal.z);if(m)for(n=0;n<3;n++)V.push(m[n].u,m[n].v);S.push(Q,Q+1,Q+2);G.push(Q,Q+1);G.push(Q,Q+2);G.push(Q+1,Q+2);Q+=3}else if(n instanceof THREE.Face4){A=i.geometry.vertices[n.a].position;L=i.geometry.vertices[n.b].position;E=i.geometry.vertices[n.c].position;O=i.geometry.vertices[n.d].position;T.push(A.x,
A.y,A.z);T.push(L.x,L.y,L.z);T.push(E.x,E.y,E.z);T.push(O.x,O.y,O.z);if(i.geometry.hasTangents){A=i.geometry.vertices[n.a].tangent;L=i.geometry.vertices[n.b].tangent;E=i.geometry.vertices[n.c].tangent;n=i.geometry.vertices[n.d].tangent;U.push(A.x,A.y,A.z,A.w);U.push(L.x,L.y,L.z,L.w);U.push(E.x,E.y,E.z,E.w);U.push(n.x,n.y,n.z,n.w)}if(D.length==4&&J)for(n=0;n<4;n++)N.push(D[n].x,D[n].y,D[n].z);else for(n=0;n<4;n++)N.push(faceNormal.x,faceNormal.y,faceNormal.z);if(m)for(n=0;n<4;n++)V.push(m[n].u,m[n].v);
S.push(Q,Q+1,Q+2);S.push(Q,Q+2,Q+3);G.push(Q,Q+1);G.push(Q,Q+2);G.push(Q,Q+3);G.push(Q+1,Q+2);G.push(Q+2,Q+3);Q+=4}}if(T.length){H.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,H.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(T),c.STATIC_DRAW);H.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,H.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(N),c.STATIC_DRAW);if(i.geometry.hasTangents){H.__webGLTangentBuffer=c.createBuffer();
c.bindBuffer(c.ARRAY_BUFFER,H.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(U),c.STATIC_DRAW)}if(V.length>0){H.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,H.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(V),c.STATIC_DRAW)}H.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,H.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(S),c.STATIC_DRAW);H.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
H.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);H.__webGLFaceCount=S.length;H.__webGLLineCount=G.length}};this.renderBuffer=function(i,p,h,w){var m,n,D,A,L,E,O,S,G;if(h instanceof THREE.MeshShaderMaterial){if(!h.program){h.program=b(h.fragment_shader,h.vertex_shader);O=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(G in h.uniforms)O.push(G);f(h.program,O);k(h.program,["position","normal","uv","tangent"])}G=
h.program}else G=x;if(G!=t){c.useProgram(G);t=G}G==x&&this.setupLights(G,p);this.loadCamera(G,i);this.loadMatrices(G);if(h instanceof THREE.MeshShaderMaterial){D=h.wireframe;A=h.wireframe_linewidth;i=G;p=h.uniforms;var T;for(m in p){S=p[m].type;O=p[m].value;T=i.uniforms[m];if(S=="i")c.uniform1i(T,O);else if(S=="f")c.uniform1f(T,O);else if(S=="v3")c.uniform3f(T,O.x,O.y,O.z);else if(S=="c")c.uniform3f(T,O.r,O.g,O.b);else if(S=="t"){c.uniform1i(T,O);if(S=p[m].texture)S.image instanceof Array&&S.image.length==
6?d(S,O):e(S,O)}}}if(h instanceof THREE.MeshPhongMaterial||h instanceof THREE.MeshLambertMaterial||h instanceof THREE.MeshBasicMaterial){m=h.color;n=h.opacity;D=h.wireframe;A=h.wireframe_linewidth;L=h.map;E=h.env_map;p=h.combine==THREE.MixOperation;i=h.reflectivity;S=h.env_map&&h.env_map.mapping instanceof THREE.CubeRefractionMapping;O=h.refraction_ratio;c.uniform4f(G.uniforms.mColor,m.r*n,m.g*n,m.b*n,n);c.uniform1i(G.uniforms.mixEnvMap,p);c.uniform1f(G.uniforms.mReflectivity,i);c.uniform1i(G.uniforms.useRefract,
S);c.uniform1f(G.uniforms.mRefractionRatio,O)}if(h instanceof THREE.MeshNormalMaterial){n=h.opacity;c.uniform1f(G.uniforms.mOpacity,n);c.uniform1i(G.uniforms.material,4)}else if(h instanceof THREE.MeshDepthMaterial){n=h.opacity;D=h.wireframe;A=h.wireframe_linewidth;c.uniform1f(G.uniforms.mOpacity,n);c.uniform1f(G.uniforms.m2Near,h.__2near);c.uniform1f(G.uniforms.mFarPlusNear,h.__farPlusNear);c.uniform1f(G.uniforms.mFarMinusNear,h.__farMinusNear);c.uniform1i(G.uniforms.material,3)}else if(h instanceof
THREE.MeshPhongMaterial){m=h.ambient;i=h.specular;h=h.shininess;c.uniform4f(G.uniforms.mAmbient,m.r,m.g,m.b,n);c.uniform4f(G.uniforms.mSpecular,i.r,i.g,i.b,n);c.uniform1f(G.uniforms.mShininess,h);c.uniform1i(G.uniforms.material,2)}else if(h instanceof THREE.MeshLambertMaterial)c.uniform1i(G.uniforms.material,1);else if(h instanceof THREE.MeshBasicMaterial)c.uniform1i(G.uniforms.material,0);else if(h instanceof THREE.MeshCubeMaterial){c.uniform1i(G.uniforms.material,5);E=h.env_map}if(L){e(L,0);c.uniform1i(G.uniforms.tMap,
0);c.uniform1i(G.uniforms.enableMap,1)}else c.uniform1i(G.uniforms.enableMap,0);if(E){d(E,1);c.uniform1i(G.uniforms.tCube,1);c.uniform1i(G.uniforms.enableCubeMap,1)}else c.uniform1i(G.uniforms.enableCubeMap,0);n=G.attributes;c.bindBuffer(c.ARRAY_BUFFER,w.__webGLVertexBuffer);c.vertexAttribPointer(n.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,w.__webGLNormalBuffer);c.vertexAttribPointer(n.normal,3,c.FLOAT,false,0,0);if(n.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLTangentBuffer);
c.vertexAttribPointer(n.tangent,4,c.FLOAT,false,0,0)}if(n.uv>=0)if(w.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLUVBuffer);c.enableVertexAttribArray(n.uv);c.vertexAttribPointer(n.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(n.uv);if(D){c.lineWidth(A);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,w.__webGLLineBuffer);c.drawElements(c.LINES,w.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,w.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,w.__webGLFaceCount,c.UNSIGNED_SHORT,
0)}};this.renderPass=function(i,p,h,w,m,n){var D,A,L,E,O;L=0;for(E=h.material.length;L<E;L++){D=h.material[L];if(D instanceof THREE.MeshFaceMaterial){D=0;for(A=w.material.length;D<A;D++)if((O=w.material[D])&&O.blending==m&&O.opacity<1==n){this.setBlending(O.blending);this.renderBuffer(i,p,O,w)}}else if((O=D)&&O.blending==m&&O.opacity<1==n){this.setBlending(O.blending);this.renderBuffer(i,p,O,w)}}};this.render=function(i,p){var h,w,m,n,D=i.lights;this.initWebGLObjects(i);this.autoClear&&this.clear();
p.autoUpdateMatrix&&p.updateMatrix();h=0;for(w=i.__webGLObjects.length;h<w;h++){m=i.__webGLObjects[h];n=m.object;m=m.buffer;if(n.visible){this.setupMatrices(n,p);this.renderPass(p,D,n,m,THREE.NormalBlending,false)}}h=0;for(w=i.__webGLObjects.length;h<w;h++){m=i.__webGLObjects[h];n=m.object;m=m.buffer;if(n.visible){this.setupMatrices(n,p);this.renderPass(p,D,n,m,THREE.AdditiveBlending,false);this.renderPass(p,D,n,m,THREE.SubtractiveBlending,false);this.renderPass(p,D,n,m,THREE.AdditiveBlending,true);
this.renderPass(p,D,n,m,THREE.SubtractiveBlending,true);this.renderPass(p,D,n,m,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(i){var p,h,w,m,n,D;if(!i.__webGLObjects){i.__webGLObjects=[];i.__webGLObjectsMap={}}p=0;for(h=i.objects.length;p<h;p++){w=i.objects[p];if(i.__webGLObjectsMap[w.id]==undefined)i.__webGLObjectsMap[w.id]={};D=i.__webGLObjectsMap[w.id];if(w instanceof THREE.Mesh)for(n in w.geometry.geometryChunks){m=w.geometry.geometryChunks[n];m.__webGLVertexBuffer||this.createBuffers(w,
n);if(D[n]==undefined){m={buffer:m,object:w};i.__webGLObjects.push(m);D[n]=1}}}};this.removeObject=function(i,p){var h,w;for(h=i.__webGLObjects.length-1;h>=0;h--){w=i.__webGLObjects[h].object;p==w&&i.__webGLObjects.splice(h,1)}};this.setupMatrices=function(i,p){i.autoUpdateMatrix&&i.updateMatrix();q.multiply(p.matrix,i.matrix);v.set(p.matrix.flatten());z.set(q.flatten());K.set(p.projectionMatrix.flatten());s=THREE.Matrix4.makeInvert3x3(q).transpose();F.set(s.m);y.set(i.matrix.flatten())};this.loadMatrices=
function(i){c.uniformMatrix4fv(i.uniforms.viewMatrix,false,v);c.uniformMatrix4fv(i.uniforms.modelViewMatrix,false,z);c.uniformMatrix4fv(i.uniforms.projectionMatrix,false,K);c.uniformMatrix3fv(i.uniforms.normalMatrix,false,F);c.uniformMatrix4fv(i.uniforms.objectMatrix,false,y)};this.loadCamera=function(i,p){c.uniform3f(i.uniforms.cameraPosition,p.position.x,p.position.y,p.position.z)};this.setBlending=function(i){switch(i){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);
break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(i,p){if(i){!p||p=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(i=="back")c.cullFace(c.BACK);else i=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
A
alteredq 已提交
177 178
THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
A
alteredq 已提交
179 180 181
var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,f=d?b.geometry:b,k=a.vertices,l=f.vertices,g=a.faces,j=f.faces,c=a.uvs;f=f.uvs;d&&b.updateMatrix();for(var t=0,x=l.length;t<x;t++){var q=new THREE.Vertex(l[t].position.clone());d&&b.matrix.multiplyVector3(q.position);k.push(q)}t=0;for(x=j.length;t<x;t++){l=j[t];var s,v=l.vertexNormals;if(l instanceof THREE.Face3)s=new THREE.Face3(l.a+e,l.b+e,l.c+e);else if(l instanceof THREE.Face4)s=new THREE.Face4(l.a+e,l.b+
e,l.c+e,l.d+e);s.centroid.copy(l.centroid);s.normal.copy(l.normal);d=0;for(k=v.length;d<k;d++){q=v[d];s.vertexNormals.push(q.clone())}s.material=l.material.slice();g.push(s)}t=0;for(x=f.length;t<x;t++){e=f[t];g=[];d=0;for(k=e.length;d<k;d++)g.push(new THREE.UV(e[d].u,e[d].v));c.push(g)}}},ImageUtils={loadTexture:function(a,b){var d=new Image;d.onload=function(){this.loaded=true};d.src=a;return new THREE.Texture(d,b)},loadArray:function(a){var b,d,e=[];b=e.loadCount=0;for(d=a.length;b<d;++b){e[b]=
new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=true};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,d,e,f,k,l,g,j,c){b=new THREE.Mesh(b,c);b.scale.x=b.scale.y=b.scale.z=d;b.position.x=e;b.position.y=f;b.position.z=k;b.rotation.x=l;b.rotation.y=g;b.rotation.z=j;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,d){d=new THREE.MeshCubeMaterial({env_map:d});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),d);a.addObject(b);return b},addPanoramaCube:function(a,
A
alteredq 已提交
182 183 184 185 186 187 188
b,d){var e=[];e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,e,true),new THREE.MeshFaceMaterial);a.addObject(mesh);
return mesh},addPanoramaCubePlanes:function(a,b,d){var e=b/2;b=new Plane(b,b);var f=Math.PI/2,k=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-e,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-e,0,0,0,f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));SceneUtils.addMesh(a,b,1,e,0,0,0,-f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,e,0,f,0,k,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,
b,1,0,-e,0,-f,0,k,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}))}},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}},fragment_shader:"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}",
vertex_shader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\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}"},
normal:{uniforms:{tNormal:{type:"t",value:2,texture:null},tAO:{type:"t",value:3,texture:null},tDisplacement:{type:"t",value:4,texture:null},uDisplacementBias:{type:"f",value:-0.5},uDisplacementScale:{type:"f",value:2.5},uPointLightPos:{type:"v3",value:new THREE.Vector3},uPointLightColor:{type:"c",value:new THREE.Color(15658734)},uDirLightPos:{type:"v3",value:new THREE.Vector3},uDirLightColor:{type:"c",value:new THREE.Color(15658734)},uAmbientLightColor:{type:"c",value:new THREE.Color(328965)},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}},fragment_shader:"uniform vec3 uDirLightPos;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightPos;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform sampler2D tNormal;\nuniform sampler2D tAO;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 normalTex = normalize( texture2D( tNormal, vUv ).xyz * 2.0 - 1.0 );\nvec3 aoTex = texture2D( tAO, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec3 pointVector = normalize( vPointLightVector );\nvec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, uShininess );\npointDiffuse  += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;\nvec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, uShininess );\ndirDiffuse  += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;\nvec4 totalLight = vec4( uAmbientColor, 1.0 );\ntotalLight += dirDiffuse + dirSpecular;\ntotalLight += pointDiffuse + pointSpecular;\ngl_FragColor = vec4( totalLight.xyz * vLightWeighting * aoTex, 1.0 );\n}",
vertex_shader:"attribute vec4 tangent;\nuniform vec3 uDirLightPos;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightPos;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientLightColor;\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;\nvarying vec3 vLightWeighting;\nvarying vec3 vPointLightVector;\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;\nvLightWeighting = uAmbientLightColor;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );\nvLightWeighting += uPointLightColor * pointLightWeighting;\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nfloat directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += uDirLightColor * directionalLightWeighting;\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}"}}},
A
alteredq 已提交
189 190 191 192 193 194 195
Cube=function(a,b,d,e,f,k,l,g){function j(z,K,F,y,o,i,p,h){var w=e||1,m=f||1,n=w+1,D=m+1;o=o/w;i=i/m;var A=c.vertices.length,L;if(z=="x"&&K=="y"||z=="y"&&K=="x")L="z";else if(z=="x"&&K=="z"||z=="z"&&K=="x")L="y";else if(z=="z"&&K=="y"||z=="y"&&K=="z")L="x";for(iy=0;iy<D;iy++)for(ix=0;ix<n;ix++){var E=new THREE.Vector3;E[z]=(ix*o-t)*F;E[K]=(iy*i-x)*y;E[L]=p;c.vertices.push(new THREE.Vertex(E))}for(iy=0;iy<m;iy++)for(ix=0;ix<w;ix++){c.faces.push(new THREE.Face4(ix+n*iy+A,ix+n*(iy+1)+A,ix+1+n*(iy+1)+
A,ix+1+n*iy+A,null,h));c.uvs.push([new THREE.UV(ix/w,iy/m),new THREE.UV(ix/w,(iy+1)/m),new THREE.UV((ix+1)/w,(iy+1)/m),new THREE.UV((ix+1)/w,iy/m)])}}THREE.Geometry.call(this);var c=this,t=a/2,x=b/2,q=d/2;l=l?-1:1;if(k!==undefined)if(k instanceof Array)this.materials=k;else{this.materials=[];for(var s=0;s<6;s++)this.materials.push([k])}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(g!=undefined)for(var v in g)if(this.sides[v]!=undefined)this.sides[v]=g[v];this.sides.px&&
j("z","y",1*l,-1,d,b,-t,this.materials[0]);this.sides.nx&&j("z","y",-1*l,-1,d,b,t,this.materials[1]);this.sides.py&&j("x","z",1*l,1,a,d,x,this.materials[2]);this.sides.ny&&j("x","z",1*l,-1,a,d,-x,this.materials[3]);this.sides.pz&&j("x","y",1*l,-1,a,b,q,this.materials[4]);this.sides.nz&&j("x","y",-1*l,-1,a,b,-q,this.materials[5]);(function(){for(var z=[],K=[],F=0,y=c.vertices.length;F<y;F++){for(var o=c.vertices[F],i=false,p=0,h=z.length;p<h;p++){var w=z[p];if(o.position.x==w.position.x&&o.position.y==
w.position.y&&o.position.z==w.position.z){K[F]=p;i=true;break}}if(!i){K[F]=z.length;z.push(new THREE.Vertex(o.position.clone()))}}F=0;for(y=c.faces.length;F<y;F++){o=c.faces[F];o.a=K[o.a];o.b=K[o.b];o.c=K[o.c];o.d=K[o.d]}c.vertices=z})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
var Cylinder=function(a,b,d,e,f){function k(c,t,x){l.vertices.push(new THREE.Vertex(new THREE.Vector3(c,t,x)))}THREE.Geometry.call(this);var l=this,g=Math.PI,j;for(j=0;j<a;j++)k(Math.sin(2*g*j/a)*b,Math.cos(2*g*j/a)*b,0);for(j=0;j<a;j++)k(Math.sin(2*g*j/a)*d,Math.cos(2*g*j/a)*d,e);for(j=0;j<a;j++)l.faces.push(new THREE.Face4(j,j+a,a+(j+1)%a,(j+1)%a));if(d!=0){k(0,0,-f);for(j=a;j<a+a/2;j++)l.faces.push(new THREE.Face4(2*a,(2*j-2*a)%a,(2*j-2*a+1)%a,(2*j-2*a+2)%a))}if(b!=0){k(0,0,e+f);for(j=a+a/2;j<
2*a;j++)l.faces.push(new THREE.Face4((2*j-2*a+2)%a+a,(2*j-2*a+1)%a+a,(2*j-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
var Plane=function(a,b,d,e){THREE.Geometry.call(this);var f,k=a/2,l=b/2;d=d||1;e=e||1;var g=d+1,j=e+1;a=a/d;var c=b/e;for(f=0;f<j;f++)for(b=0;b<g;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-k,-(f*c-l),0)));for(f=0;f<e;f++)for(b=0;b<d;b++){this.faces.push(new THREE.Face4(b+g*f,b+g*(f+1),b+1+g*(f+1),b+1+g*f));this.uvs.push([new THREE.UV(b/d,f/e),new THREE.UV(b/d,(f+1)/e),new THREE.UV((b+1)/d,(f+1)/e),new THREE.UV((b+1)/d,f/e)])}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};
A
alteredq 已提交
196
Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
A
alteredq 已提交
197 198 199
var Sphere=function(a,b,d){THREE.Geometry.call(this);var e,f=Math.PI,k=Math.max(3,b||8),l=Math.max(2,d||6);b=[];for(d=0;d<l+1;d++){e=d/l;var g=a*Math.cos(e*f),j=a*Math.sin(e*f),c=[],t=0;for(e=0;e<k;e++){var x=2*e/k,q=j*Math.sin(x*f);x=j*Math.cos(x*f);(d==0||d==l)&&e>0||(t=this.vertices.push(new THREE.Vertex(new THREE.Vector3(x,g,q)))-1);c.push(t)}b.push(c)}var s,v;a=b.length;for(d=0;d<a;d++){f=b[d].length;if(d>0)for(e=0;e<f;e++){j=e==f-1;k=b[d][j?0:e+1];l=b[d][j?f-1:e];g=b[d-1][j?f-1:e];j=b[d-1][j?
0:e+1];t=d/(a-1);x=(d-1)/(a-1);s=(e+1)/f;q=e/f;c=new THREE.UV(1-s,t);t=new THREE.UV(1-q,t);q=new THREE.UV(1-q,x);var z=new THREE.UV(1-s,x);if(d<b.length-1){x=this.vertices[k].position.clone();s=this.vertices[l].position.clone();v=this.vertices[g].position.clone();x.normalize();s.normalize();v.normalize();this.faces.push(new THREE.Face3(k,l,g,[new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(s.x,s.y,s.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,t,q])}if(d>1){x=this.vertices[k].position.clone();
s=this.vertices[g].position.clone();v=this.vertices[j].position.clone();x.normalize();s.normalize();v.normalize();this.faces.push(new THREE.Face3(k,g,j,[new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(s.x,s.y,s.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,q,z])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial()};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
A
alteredq 已提交
200 201 202
THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?this.addStatusElement():null};
THREE.Loader.prototype={addStatusElement:function(){var a=document.createElement("div");a.style.fontSize="0.8em";a.style.textAlign="left";a.style.background="#b00";a.style.color="#fff";a.style.width="140px";a.style.padding="0.25em 0.25em 0.25em 0.5em";a.style.position="absolute";a.style.right="0px";a.style.top="0px";a.style.zIndex=1E3;a.innerHTML="Loading ...";return a},updateProgress:function(a){var b="Loaded ";b+=a.total?(100*a.loaded/a.total).toFixed(0)+"%":(a.loaded/1E3).toFixed(2)+" KB";this.statusDomElement.innerHTML=
b},loadAsciiOld:function(a,b){var d=document.createElement("script");d.type="text/javascript";d.onload=b;d.src=a;document.getElementsByTagName("head")[0].appendChild(d)},loadAscii:function(a,b,d){var e=(new Date).getTime();a=new Worker(a);a.onmessage=function(f){THREE.Loader.prototype.createModel(f.data,b,d)};a.postMessage(e)},loadBinary:function(a,b,d){var e=(new Date).getTime();a=new Worker(a);var f=this.showProgress?THREE.Loader.prototype.updateProgress:null;a.onmessage=function(k){THREE.Loader.prototype.loadAjaxBuffers(k.data.buffers,
A
alteredq 已提交
203 204 205 206 207 208 209 210 211 212 213 214 215
k.data.materials,b,d,f)};a.onerror=function(k){alert("worker.onerror: "+k.message+"\n"+k.data);k.preventDefault()};a.postMessage(e)},loadAjaxBuffers:function(a,b,d,e,f){var k=new XMLHttpRequest,l=e+"/"+a,g=0;k.onreadystatechange=function(){if(k.readyState==4)k.status==200||k.status==0?THREE.Loader.prototype.createBinModel(k.responseText,d,e,b):alert("Couldn't load ["+l+"] ["+k.status+"]");else if(k.readyState==3){if(f){if(g==0)g=k.getResponseHeader("Content-Length");f({total:g,loaded:k.responseText.length})}}else if(k.readyState==
2)g=k.getResponseHeader("Content-Length")};k.open("GET",l,true);k.overrideMimeType("text/plain; charset=x-user-defined");k.setRequestHeader("Content-Type","text/plain");k.send(null)},createBinModel:function(a,b,d,e){var f=function(k){function l(r,u){var B=t(r,u),M=t(r,u+1),X=t(r,u+2),Y=t(r,u+3),ea=(Y<<1&255|X>>7)-127;B=(X&127)<<16|M<<8|B;if(B==0&&ea==-127)return 0;return(1-2*(Y>>7))*(1+B*Math.pow(2,-23))*Math.pow(2,ea)}function g(r,u){var B=t(r,u),M=t(r,u+1),X=t(r,u+2);return(t(r,u+3)<<24)+(X<<16)+
(M<<8)+B}function j(r,u){var B=t(r,u);return(t(r,u+1)<<8)+B}function c(r,u){var B=t(r,u);return B>127?B-256:B}function t(r,u){return r.charCodeAt(u)&255}function x(r){var u,B,M;u=g(a,r);B=g(a,r+h);M=g(a,r+w);r=j(a,r+m);THREE.Loader.prototype.f3(F,u,B,M,r)}function q(r){var u,B,M,X,Y,ea;u=g(a,r);B=g(a,r+h);M=g(a,r+w);X=j(a,r+m);Y=g(a,r+n);ea=g(a,r+D);r=g(a,r+A);THREE.Loader.prototype.f3n(F,i,u,B,M,X,Y,ea,r)}function s(r){var u,B,M,X;u=g(a,r);B=g(a,r+L);M=g(a,r+E);X=g(a,r+O);r=j(a,r+S);THREE.Loader.prototype.f4(F,
u,B,M,X,r)}function v(r){var u,B,M,X,Y,ea,ma,oa;u=g(a,r);B=g(a,r+L);M=g(a,r+E);X=g(a,r+O);Y=j(a,r+S);ea=g(a,r+G);ma=g(a,r+T);oa=g(a,r+N);r=g(a,r+U);THREE.Loader.prototype.f4n(F,i,u,B,M,X,Y,ea,ma,oa,r)}function z(r){var u,B;u=g(a,r);B=g(a,r+V);r=g(a,r+Q);THREE.Loader.prototype.uv3(F,p[u*2],p[u*2+1],p[B*2],p[B*2+1],p[r*2],p[r*2+1])}function K(r){var u,B,M;u=g(a,r);B=g(a,r+H);M=g(a,r+J);r=g(a,r+$);THREE.Loader.prototype.uv4(F,p[u*2],p[u*2+1],p[B*2],p[B*2+1],p[M*2],p[M*2+1],p[r*2],p[r*2+1])}var F=this,
y=0,o,i=[],p=[],h,w,m,n,D,A,L,E,O,S,G,T,N,U,V,Q,H,J,$;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(F,e,k);o={signature:a.substr(y,8),header_bytes:t(a,y+8),vertex_coordinate_bytes:t(a,y+9),normal_coordinate_bytes:t(a,y+10),uv_coordinate_bytes:t(a,y+11),vertex_index_bytes:t(a,y+12),normal_index_bytes:t(a,y+13),uv_index_bytes:t(a,y+14),material_index_bytes:t(a,y+15),nvertices:g(a,y+16),nnormals:g(a,y+16+4),nuvs:g(a,y+16+8),ntri_flat:g(a,y+16+12),ntri_smooth:g(a,y+16+16),ntri_flat_uv:g(a,
y+16+20),ntri_smooth_uv:g(a,y+16+24),nquad_flat:g(a,y+16+28),nquad_smooth:g(a,y+16+32),nquad_flat_uv:g(a,y+16+36),nquad_smooth_uv:g(a,y+16+40)};y+=o.header_bytes;h=o.vertex_index_bytes;w=o.vertex_index_bytes*2;m=o.vertex_index_bytes*3;n=o.vertex_index_bytes*3+o.material_index_bytes;D=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes;A=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*2;L=o.vertex_index_bytes;E=o.vertex_index_bytes*2;O=o.vertex_index_bytes*3;S=o.vertex_index_bytes*
4;G=o.vertex_index_bytes*4+o.material_index_bytes;T=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes;N=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*2;U=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*3;V=o.uv_index_bytes;Q=o.uv_index_bytes*2;H=o.uv_index_bytes;J=o.uv_index_bytes*2;$=o.uv_index_bytes*3;y+=function(r){var u,B,M,X=o.vertex_coordinate_bytes*3,Y=r+o.nvertices*X;for(r=r;r<Y;r+=X){u=l(a,r);B=l(a,r+o.vertex_coordinate_bytes);M=l(a,
r+o.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(F,u,B,M)}return o.nvertices*X}(y);y+=function(r){var u,B,M,X=o.normal_coordinate_bytes*3,Y=r+o.nnormals*X;for(r=r;r<Y;r+=X){u=c(a,r);B=c(a,r+o.normal_coordinate_bytes);M=c(a,r+o.normal_coordinate_bytes*2);i.push(u/127,B/127,M/127)}return o.nnormals*X}(y);y+=function(r){var u,B,M=o.uv_coordinate_bytes*2,X=r+o.nuvs*M;for(r=r;r<X;r+=M){u=l(a,r);B=l(a,r+o.uv_coordinate_bytes);p.push(u,B)}return o.nuvs*M}(y);y+=function(r){var u,B=o.vertex_index_bytes*
3+o.material_index_bytes,M=r+o.ntri_flat*B;for(u=r;u<M;u+=B)x(u);return M-r}(y);y+=function(r){var u,B=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*3,M=r+o.ntri_smooth*B;for(u=r;u<M;u+=B)q(u);return M-r}(y);y+=function(r){var u,B=o.vertex_index_bytes*3+o.material_index_bytes,M=B+o.uv_index_bytes*3,X=r+o.ntri_flat_uv*M;for(u=r;u<X;u+=M){x(u);z(u+B)}return X-r}(y);y+=function(r){var u,B=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*3,M=B+o.uv_index_bytes*3,
X=r+o.ntri_smooth_uv*M;for(u=r;u<X;u+=M){q(u);z(u+B)}return X-r}(y);y+=function(r){var u,B=o.vertex_index_bytes*4+o.material_index_bytes,M=r+o.nquad_flat*B;for(u=r;u<M;u+=B)s(u);return M-r}(y);y+=function(r){var u,B=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*4,M=r+o.nquad_smooth*B;for(u=r;u<M;u+=B)v(u);return M-r}(y);y+=function(r){var u,B=o.vertex_index_bytes*4+o.material_index_bytes,M=B+o.uv_index_bytes*4,X=r+o.nquad_flat_uv*M;for(u=r;u<X;u+=M){s(u);K(u+B)}return X-r}(y);
y+=function(r){var u,B=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*4,M=B+o.uv_index_bytes*4,X=r+o.nquad_smooth_uv*M;for(u=r;u<X;u+=M){v(u);K(u+B)}return X-r}(y);this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};f.prototype=new THREE.Geometry;f.prototype.constructor=f;b(new f(d))},createModel:function(a,b,d){var e=function(f){var k=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(k,a.materials,f);(function(){var l,g,j,c,t;l=0;for(g=
a.vertices.length;l<g;l+=3){j=a.vertices[l];c=a.vertices[l+1];t=a.vertices[l+2];THREE.Loader.prototype.v(k,j,c,t)}})();(function(){function l(v,z){THREE.Loader.prototype.f3(k,v[z],v[z+1],v[z+2],v[z+3])}function g(v,z){THREE.Loader.prototype.f3n(k,a.normals,v[z],v[z+1],v[z+2],v[z+3],v[z+4],v[z+5],v[z+6])}function j(v,z){THREE.Loader.prototype.f4(k,v[z],v[z+1],v[z+2],v[z+3],v[z+4])}function c(v,z){THREE.Loader.prototype.f4n(k,a.normals,v[z],v[z+1],v[z+2],v[z+3],v[z+4],v[z+5],v[z+6],v[z+7],v[z+8])}function t(v,
z){var K,F,y;K=v[z];F=v[z+1];y=v[z+2];THREE.Loader.prototype.uv3(k,a.uvs[K*2],a.uvs[K*2+1],a.uvs[F*2],a.uvs[F*2+1],a.uvs[y*2],a.uvs[y*2+1])}function x(v,z){var K,F,y,o;K=v[z];F=v[z+1];y=v[z+2];o=v[z+3];THREE.Loader.prototype.uv4(k,a.uvs[K*2],a.uvs[K*2+1],a.uvs[F*2],a.uvs[F*2+1],a.uvs[y*2],a.uvs[y*2+1],a.uvs[o*2],a.uvs[o*2+1])}var q,s;q=0;for(s=a.triangles.length;q<s;q+=4)l(a.triangles,q);q=0;for(s=a.triangles_uv.length;q<s;q+=7){l(a.triangles_uv,q);t(a.triangles_uv,q+4)}q=0;for(s=a.triangles_n.length;q<
A
alteredq 已提交
216
s;q+=7)g(a.triangles_n,q);q=0;for(s=a.triangles_n_uv.length;q<s;q+=10){g(a.triangles_n_uv,q);t(a.triangles_n_uv,q+7)}q=0;for(s=a.quads.length;q<s;q+=5)j(a.quads,q);q=0;for(s=a.quads_uv.length;q<s;q+=9){j(a.quads_uv,q);x(a.quads_uv,q+5)}q=0;for(s=a.quads_n.length;q<s;q+=9)c(a.quads_n,q);q=0;for(s=a.quads_n_uv.length;q<s;q+=13){c(a.quads_n_uv,q);x(a.quads_n_uv,q+9)}})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};e.prototype=new THREE.Geometry;e.prototype.constructor=
A
alteredq 已提交
217 218 219 220
e;b(new e(d))},v:function(a,b,d,e){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,d,e)))},f3:function(a,b,d,e,f){a.faces.push(new THREE.Face3(b,d,e,null,a.materials[f]))},f4:function(a,b,d,e,f,k){a.faces.push(new THREE.Face4(b,d,e,f,null,a.materials[k]))},f3n:function(a,b,d,e,f,k,l,g,j){k=a.materials[k];var c=b[g*3],t=b[g*3+1];g=b[g*3+2];var x=b[j*3],q=b[j*3+1];j=b[j*3+2];a.faces.push(new THREE.Face3(d,e,f,[new THREE.Vector3(b[l*3],b[l*3+1],b[l*3+2]),new THREE.Vector3(c,t,g),new THREE.Vector3(x,
q,j)],k))},f4n:function(a,b,d,e,f,k,l,g,j,c,t){l=a.materials[l];var x=b[j*3],q=b[j*3+1];j=b[j*3+2];var s=b[c*3],v=b[c*3+1];c=b[c*3+2];var z=b[t*3],K=b[t*3+1];t=b[t*3+2];a.faces.push(new THREE.Face4(d,e,f,k,[new THREE.Vector3(b[g*3],b[g*3+1],b[g*3+2]),new THREE.Vector3(x,q,j),new THREE.Vector3(s,v,c),new THREE.Vector3(z,K,t)],l))},uv3:function(a,b,d,e,f,k,l){var g=[];g.push(new THREE.UV(b,d));g.push(new THREE.UV(e,f));g.push(new THREE.UV(k,l));a.uvs.push(g)},uv4:function(a,b,d,e,f,k,l,g,j){var c=[];
c.push(new THREE.UV(b,d));c.push(new THREE.UV(e,f));c.push(new THREE.UV(k,l));c.push(new THREE.UV(g,j));a.uvs.push(c)},init_materials:function(a,b,d){a.materials=[];for(var e=0;e<b.length;++e)a.materials[e]=[THREE.Loader.prototype.createMaterial(b[e],d)]},createMaterial:function(a,b){function d(k){k=Math.log(k)/Math.LN2;return Math.floor(k)==k}var e,f;if(a.map_diffuse&&b){f=document.createElement("canvas");e=new THREE.MeshLambertMaterial({map:new THREE.Texture(f)});f=new Image;f.onload=function(){if(!d(this.width)||
!d(this.height)){var k=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),l=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));e.map.image.width=k;e.map.image.height=l;e.map.image.getContext("2d").drawImage(this,0,0,k,l)}else e.map.image=this;e.map.image.loaded=1};f.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){f=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;e=new THREE.MeshLambertMaterial({color:f,opacity:a.transparency})}else e=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):
A
alteredq 已提交
221
new THREE.MeshLambertMaterial({color:15658734});return e}};