mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-23 03:45:56 +10:00
For the moment, only one type of fog is baked into shader, depending on scene.fog initial value. If use case arise for dynamic fog type switching, this could be changed, though than both fogs would need to be computed all the time :S.
233 lines
110 KiB
JavaScript
233 lines
110 KiB
JavaScript
// 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,e){this.r=a;this.g=b;this.b=e;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,e){this.x=a||0;this.y=b||0;this.z=e||0};
|
|
THREE.Vector3.prototype={set:function(a,b,e){this.x=a;this.y=b;this.z=e;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,e=this.y,d=this.z;this.x=e*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-e*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,e=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+e*e+a*a)},distanceToSquared:function(a){var b=this.x-a.x,e=this.y-a.y;a=this.z-a.z;return b*b+e*e+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,e,d){this.x=a||0;this.y=b||0;this.z=e||0;this.w=d||1};
|
|
THREE.Vector4.prototype={set:function(a,b,e,d){this.x=a;this.y=b;this.z=e;this.w=d;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};
|
|
THREE.Ray.prototype={intersectScene:function(a){var b,e,d=a.objects,g=[];a=0;for(b=d.length;a<b;a++){e=d[a];if(e instanceof THREE.Mesh)g=g.concat(this.intersectObject(e))}g.sort(function(f,k){return f.distance-k.distance});return g},intersectObject:function(a){function b(L,v,E,m){m=m.clone().subSelf(v);E=E.clone().subSelf(v);var O=L.clone().subSelf(v);L=m.dot(m);v=m.dot(E);m=m.dot(O);var i=E.dot(E);E=E.dot(O);O=1/(L*i-v*v);i=(i*m-v*E)*O;L=(L*E-v*m)*O;return i>0&&L>0&&i+L<1}var e,d,g,f,k,h,j,c,w,B,
|
|
t,u=a.geometry,x=u.vertices,z=[];e=0;for(d=u.faces.length;e<d;e++){g=u.faces[e];B=this.origin.clone();t=this.direction.clone();f=a.matrix.multiplyVector3(x[g.a].position.clone());k=a.matrix.multiplyVector3(x[g.b].position.clone());h=a.matrix.multiplyVector3(x[g.c].position.clone());j=g instanceof THREE.Face4?a.matrix.multiplyVector3(x[g.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(g.normal.clone());w=t.dot(c);if(w<0){c=c.dot((new THREE.Vector3).sub(f,B))/w;B=B.addSelf(t.multiplyScalar(c));
|
|
if(g instanceof THREE.Face3){if(b(B,f,k,h)){g={distance:this.origin.distanceTo(B),point:B,face:g,object:a};z.push(g)}}else if(g instanceof THREE.Face4)if(b(B,f,k,j)||b(B,k,h,j)){g={distance:this.origin.distanceTo(B),point:B,face:g,object:a};z.push(g)}}}return z}};
|
|
THREE.Rectangle=function(){function a(){f=d-b;k=g-e}var b,e,d,g,f,k,h=true;this.getX=function(){return b};this.getY=function(){return e};this.getWidth=function(){return f};this.getHeight=function(){return k};this.getLeft=function(){return b};this.getTop=function(){return e};this.getRight=function(){return d};this.getBottom=function(){return g};this.set=function(j,c,w,B){h=false;b=j;e=c;d=w;g=B;a()};this.addPoint=function(j,c){if(h){h=false;b=j;e=c;d=j;g=c}else{b=b<j?b:j;e=e<c?e:c;d=d>j?d:j;g=g>c?
|
|
g:c}a()};this.add3Points=function(j,c,w,B,t,u){if(h){h=false;b=j<w?j<t?j:t:w<t?w:t;e=c<B?c<u?c:u:B<u?B:u;d=j>w?j>t?j:t:w>t?w:t;g=c>B?c>u?c:u:B>u?B:u}else{b=j<w?j<t?j<b?j:b:t<b?t:b:w<t?w<b?w:b:t<b?t:b;e=c<B?c<u?c<e?c:e:u<e?u:e:B<u?B<e?B:e:u<e?u:e;d=j>w?j>t?j>d?j:d:t>d?t:d:w>t?w>d?w:d:t>d?t:d;g=c>B?c>u?c>g?c:g:u>g?u:g:B>u?B>g?B:g:u>g?u:g}a()};this.addRectangle=function(j){if(h){h=false;b=j.getLeft();e=j.getTop();d=j.getRight();g=j.getBottom()}else{b=b<j.getLeft()?b:j.getLeft();e=e<j.getTop()?e:j.getTop();
|
|
d=d>j.getRight()?d:j.getRight();g=g>j.getBottom()?g:j.getBottom()}a()};this.inflate=function(j){b-=j;e-=j;d+=j;g+=j;a()};this.minSelf=function(j){b=b>j.getLeft()?b:j.getLeft();e=e>j.getTop()?e:j.getTop();d=d<j.getRight()?d:j.getRight();g=g<j.getBottom()?g:j.getBottom();a()};this.instersects=function(j){return Math.min(d,j.getRight())-Math.max(b,j.getLeft())>=0&&Math.min(g,j.getBottom())-Math.max(e,j.getTop())>=0};this.empty=function(){h=true;g=d=e=b=0;a()};this.isEmpty=function(){return h};this.toString=
|
|
function(){return"THREE.Rectangle ( left: "+b+", right: "+d+", top: "+e+", bottom: "+g+", width: "+f+", height: "+k+" )"}};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,e,d,g,f,k,h,j,c,w,B,t,u,x,z){this.n11=a||1;this.n12=b||0;this.n13=e||0;this.n14=d||0;this.n21=g||0;this.n22=f||1;this.n23=k||0;this.n24=h||0;this.n31=j||0;this.n32=c||0;this.n33=w||1;this.n34=B||0;this.n41=t||0;this.n42=u||0;this.n43=x||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,e,d,g,f,k,h,j,c,w,B,t,u,x,z){this.n11=a;this.n12=b;this.n13=e;this.n14=d;this.n21=g;this.n22=f;this.n23=k;this.n24=h;this.n31=j;this.n32=c;this.n33=w;this.n34=B;this.n41=t;this.n42=u;this.n43=x;this.n44=z;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
|
|
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,e){var d=new THREE.Vector3,g=new THREE.Vector3,f=new THREE.Vector3;f.sub(a,b).normalize();d.cross(e,f).normalize();g.cross(f,d).normalize();this.n11=d.x;this.n12=d.y;this.n13=d.z;this.n14=-d.dot(a);this.n21=g.x;this.n22=g.y;this.n23=g.z;this.n24=-g.dot(a);this.n31=f.x;
|
|
this.n32=f.y;this.n33=f.z;this.n34=-f.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,e=a.y,d=a.z,g=1/(this.n41*b+this.n42*e+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*e+this.n13*d+this.n14)*g;a.y=(this.n21*b+this.n22*e+this.n23*d+this.n24)*g;a.z=(this.n31*b+this.n32*e+this.n33*d+this.n34)*g;return a},multiplyVector4:function(a){var b=a.x,e=a.y,d=a.z,g=a.w;a.x=this.n11*b+this.n12*e+this.n13*d+this.n14*g;a.y=this.n21*b+this.n22*e+this.n23*d+this.n24*
|
|
g;a.z=this.n31*b+this.n32*e+this.n33*d+this.n34*g;a.w=this.n41*b+this.n42*e+this.n43*d+this.n44*g;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 e=a.n11,d=a.n12,g=a.n13,f=a.n14,k=a.n21,h=a.n22,j=a.n23,c=a.n24,w=a.n31,B=a.n32,
|
|
t=a.n33,u=a.n34,x=a.n41,z=a.n42,L=a.n43,v=a.n44,E=b.n11,m=b.n12,O=b.n13,i=b.n14,r=b.n21,n=b.n22,l=b.n23,s=b.n24,o=b.n31,A=b.n32,G=b.n33,C=b.n34,H=b.n41,V=b.n42,D=b.n43,Q=b.n44;this.n11=e*E+d*r+g*o+f*H;this.n12=e*m+d*n+g*A+f*V;this.n13=e*O+d*l+g*G+f*D;this.n14=e*i+d*s+g*C+f*Q;this.n21=k*E+h*r+j*o+c*H;this.n22=k*m+h*n+j*A+c*V;this.n23=k*O+h*l+j*G+c*D;this.n24=k*i+h*s+j*C+c*Q;this.n31=w*E+B*r+t*o+u*H;this.n32=w*m+B*n+t*A+u*V;this.n33=w*O+B*l+t*G+u*D;this.n34=w*i+B*s+t*C+u*Q;this.n41=x*E+z*r+L*o+v*H;
|
|
this.n42=x*m+z*n+L*A+v*V;this.n43=x*O+z*l+L*G+v*D;this.n44=x*i+z*s+L*C+v*Q;return this},multiplySelf:function(a){var b=this.n11,e=this.n12,d=this.n13,g=this.n14,f=this.n21,k=this.n22,h=this.n23,j=this.n24,c=this.n31,w=this.n32,B=this.n33,t=this.n34,u=this.n41,x=this.n42,z=this.n43,L=this.n44,v=a.n11,E=a.n21,m=a.n31,O=a.n41,i=a.n12,r=a.n22,n=a.n32,l=a.n42,s=a.n13,o=a.n23,A=a.n33,G=a.n43,C=a.n14,H=a.n24,V=a.n34;a=a.n44;this.n11=b*v+e*E+d*m+g*O;this.n12=b*i+e*r+d*n+g*l;this.n13=b*s+e*o+d*A+g*G;this.n14=
|
|
b*C+e*H+d*V+g*a;this.n21=f*v+k*E+h*m+j*O;this.n22=f*i+k*r+h*n+j*l;this.n23=f*s+k*o+h*A+j*G;this.n24=f*C+k*H+h*V+j*a;this.n31=c*v+w*E+B*m+t*O;this.n32=c*i+w*r+B*n+t*l;this.n33=c*s+w*o+B*A+t*G;this.n34=c*C+w*H+B*V+t*a;this.n41=u*v+x*E+z*m+L*O;this.n42=u*i+x*r+z*n+L*l;this.n43=u*s+x*o+z*A+L*G;this.n44=u*C+x*H+z*V+L*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
|
|
a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){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,e,d){var g=b[e];b[e]=b[d];
|
|
b[d]=g}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,e){var d=new THREE.Matrix4;d.n14=a;d.n24=b;d.n34=e;return d};
|
|
THREE.Matrix4.scaleMatrix=function(a,b,e){var d=new THREE.Matrix4;d.n11=a;d.n22=b;d.n33=e;return d};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};
|
|
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var e=new THREE.Matrix4,d=Math.cos(b),g=Math.sin(b),f=1-d,k=a.x,h=a.y,j=a.z;e.n11=f*k*k+d;e.n12=f*k*h-g*j;e.n13=f*k*j+g*h;e.n21=f*k*h+g*j;e.n22=f*h*h+d;e.n23=f*h*j-g*k;e.n31=f*k*j-g*h;e.n32=f*h*j+g*k;e.n33=f*j*j+d;return e};
|
|
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};
|
|
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var e=b[10]*b[5]-b[6]*b[9],d=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],f=-b[10]*b[4]+b[6]*b[8],k=b[10]*b[0]-b[2]*b[8],h=-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],w=b[5]*b[0]-b[1]*b[4];b=b[0]*e+b[1]*f+b[2]*j;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*e;a.m[1]=b*d;a.m[2]=b*g;a.m[3]=b*f;a.m[4]=b*k;a.m[5]=b*h;a.m[6]=b*j;a.m[7]=b*c;a.m[8]=b*w;return a};
|
|
THREE.Matrix4.makeFrustum=function(a,b,e,d,g,f){var k,h,j;k=new THREE.Matrix4;h=2*g/(b-a);j=2*g/(d-e);a=(b+a)/(b-a);e=(d+e)/(d-e);d=-(f+g)/(f-g);g=-2*f*g/(f-g);k.n11=h;k.n12=0;k.n13=a;k.n14=0;k.n21=0;k.n22=j;k.n23=e;k.n24=0;k.n31=0;k.n32=0;k.n33=d;k.n34=g;k.n41=0;k.n42=0;k.n43=-1;k.n44=0;return k};THREE.Matrix4.makePerspective=function(a,b,e,d){var g;a=e*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,e,d)};
|
|
THREE.Matrix4.makeOrtho=function(a,b,e,d,g,f){var k,h,j,c;k=new THREE.Matrix4;h=b-a;j=e-d;c=f-g;a=(b+a)/h;e=(e+d)/j;g=(f+g)/c;k.n11=2/h;k.n12=0;k.n13=0;k.n14=-a;k.n21=0;k.n22=2/j;k.n23=0;k.n24=-e;k.n31=0;k.n32=0;k.n33=-2/c;k.n34=-g;k.n41=0;k.n42=0;k.n43=0;k.n44=1;return k};
|
|
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,e,d,g){this.a=a;this.b=b;this.c=e;this.centroid=new THREE.Vector3;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.materials=g instanceof Array?g:[g]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
|
|
THREE.Face4=function(a,b,e,d,g,f){this.a=a;this.b=b;this.c=e;this.d=d;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.materials=f instanceof Array?f:[f]};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.boundingSphere=this.boundingBox=null;this.geometryChunks={};this.hasTangents=false};
|
|
THREE.Geometry.prototype={computeCentroids:function(){var a,b,e;a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];e.centroid.set(0,0,0);if(e instanceof THREE.Face3){e.centroid.addSelf(this.vertices[e.a].position);e.centroid.addSelf(this.vertices[e.b].position);e.centroid.addSelf(this.vertices[e.c].position);e.centroid.divideScalar(3)}else if(e instanceof THREE.Face4){e.centroid.addSelf(this.vertices[e.a].position);e.centroid.addSelf(this.vertices[e.b].position);e.centroid.addSelf(this.vertices[e.c].position);
|
|
e.centroid.addSelf(this.vertices[e.d].position);e.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,e,d,g,f,k,h=new THREE.Vector3,j=new THREE.Vector3;d=0;for(g=this.vertices.length;d<g;d++){f=this.vertices[d];f.normal.set(0,0,0)}d=0;for(g=this.faces.length;d<g;d++){f=this.faces[d];if(a&&f.vertexNormals.length){h.set(0,0,0);b=0;for(e=f.normal.length;b<e;b++)h.addSelf(f.vertexNormals[b]);h.divideScalar(3)}else{b=this.vertices[f.a];e=this.vertices[f.b];k=this.vertices[f.c];h.sub(k.position,
|
|
e.position);j.sub(b.position,e.position);h.crossSelf(j)}h.isZero()||h.normalize();f.normal.copy(h)}},computeVertexNormals:function(){var a,b=[],e,d;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(e=this.faces.length;a<e;a++){d=this.faces[a];if(d instanceof THREE.Face3){b[d.a].addSelf(d.normal);b[d.b].addSelf(d.normal);b[d.c].addSelf(d.normal)}else if(d instanceof THREE.Face4){b[d.a].addSelf(d.normal);b[d.b].addSelf(d.normal);b[d.c].addSelf(d.normal);b[d.d].addSelf(d.normal)}}a=
|
|
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(e=this.faces.length;a<e;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0]=b[d.a].clone();d.vertexNormals[1]=b[d.b].clone();d.vertexNormals[2]=b[d.c].clone()}else if(d instanceof THREE.Face4){d.vertexNormals[0]=b[d.a].clone();d.vertexNormals[1]=b[d.b].clone();d.vertexNormals[2]=b[d.c].clone();d.vertexNormals[3]=b[d.d].clone()}}},computeTangents:function(){function a(C,H,V,D){f=C.vertices[H].position;k=C.vertices[V].position;
|
|
h=C.vertices[D].position;j=g[0];c=g[1];w=g[2];B=k.x-f.x;t=h.x-f.x;u=k.y-f.y;x=h.y-f.y;z=k.z-f.z;L=h.z-f.z;v=c.u-j.u;E=w.u-j.u;m=c.v-j.v;O=w.v-j.v;i=1/(v*O-E*m);s.set((O*B-m*t)*i,(O*u-m*x)*i,(O*z-m*L)*i);o.set((v*t-E*B)*i,(v*x-E*u)*i,(v*L-E*z)*i);n[H].addSelf(s);n[V].addSelf(s);n[D].addSelf(s);l[H].addSelf(o);l[V].addSelf(o);l[D].addSelf(o)}var b,e,d,g,f,k,h,j,c,w,B,t,u,x,z,L,v,E,m,O,i,r,n=[],l=[],s=new THREE.Vector3,o=new THREE.Vector3,A=new THREE.Vector3,G=new THREE.Vector3;r=new THREE.Vector3;b=
|
|
0;for(e=this.vertices.length;b<e;b++){n[b]=new THREE.Vector3;l[b]=new THREE.Vector3}b=0;for(e=this.faces.length;b<e;b++){d=this.faces[b];g=this.uvs[b];if(d instanceof THREE.Face3){a(this,d.a,d.b,d.c);this.vertices[d.a].normal.copy(d.vertexNormals[0]);this.vertices[d.b].normal.copy(d.vertexNormals[1]);this.vertices[d.c].normal.copy(d.vertexNormals[2])}else if(d instanceof THREE.Face4){a(this,d.a,d.b,d.c);this.vertices[d.a].normal.copy(d.vertexNormals[0]);this.vertices[d.b].normal.copy(d.vertexNormals[1]);
|
|
this.vertices[d.c].normal.copy(d.vertexNormals[2]);this.vertices[d.d].normal.copy(d.vertexNormals[3])}}b=0;for(e=this.vertices.length;b<e;b++){r.copy(this.vertices[b].normal);d=n[b];A.copy(d);A.subSelf(r.multiplyScalar(r.dot(d))).normalize();G.cross(this.vertices[b].normal,d);test=G.dot(l[b]);d=test<0?-1:1;this.vertices[b].tangent.set(A.x,A.y,A.z,d)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
|
|
y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,e=this.vertices.length;b<e;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<
|
|
this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,e=this.vertices.length;b<e;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(c){var w=[];b=0;for(e=c.length;b<e;b++)c[b]==undefined?w.push("undefined"):w.push(c[b].toString());return w.join("_")}
|
|
var b,e,d,g,f,k,h,j={};d=0;for(g=this.faces.length;d<g;d++){f=this.faces[d];materials=f.materials;k=a(materials);if(j[k]==undefined)j[k]={hash:k,counter:0};h=j[k].hash+"_"+j[k].counter;if(this.geometryChunks[h]==undefined)this.geometryChunks[h]={faces:[],materials:materials,vertices:0};f=f instanceof THREE.Face3?3:4;if(this.geometryChunks[h].vertices+f>65535){j[k].counter+=1;h=j[k].hash+"_"+j[k].counter;if(this.geometryChunks[h]==undefined)this.geometryChunks[h]={faces:[],materials:materials,vertices:0}}this.geometryChunks[h].faces.push(d);
|
|
this.geometryChunks[h].vertices+=f}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
|
|
THREE.Camera=function(a,b,e,d){this.fov=a;this.aspect=b;this.near=e;this.far=d;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=null;this.autoUpdateMatrix=true;this.translateX=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);g.cross(g.clone(),this.up);this.position.addSelf(g);this.target.position.addSelf(g)};this.translateZ=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);
|
|
this.position.subSelf(g);this.target.position.subSelf(g)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix();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.visible=this.autoUpdateMatrix=true};
|
|
THREE.Object3D.prototype={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.materials=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.materials=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;
|
|
THREE.Line.prototype.constructor=THREE.Line;THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;this.geometry.boundingSphere||this.geometry.computeBoundingSphere()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
|
|
THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16777215);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}};
|
|
THREE.LineBasicMaterial.prototype={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(16777215);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;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.fog!==undefined)this.fog=a.fog;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}};
|
|
THREE.MeshBasicMaterial.prototype={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(16777215);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;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.fog!==undefined)this.fog=a.fog;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}};
|
|
THREE.MeshLambertMaterial.prototype={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(16777215);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.fog=true;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.fog!==undefined)this.fog=a.fog;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}};
|
|
THREE.MeshPhongMaterial.prototype={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.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.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}};THREE.MeshDepthMaterial.prototype={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}};THREE.MeshNormalMaterial.prototype={toString:function(){return"THREE.MeshNormalMaterial"}};THREE.MeshFaceMaterial=function(){};THREE.MeshFaceMaterial.prototype={toString:function(){return"THREE.MeshFaceMaterial"}};
|
|
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}};
|
|
THREE.MeshShaderMaterial.prototype={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(16777215);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}};
|
|
THREE.ParticleBasicMaterial.prototype={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(16777215);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}};
|
|
THREE.ParticleCircleMaterial.prototype={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};THREE.ParticleDOMMaterial.prototype={toString:function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
|
|
THREE.Texture=function(a,b,e,d,g,f){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=e!==undefined?e:THREE.ClampToEdgeWrapping;this.wrap_t=d!==undefined?d:THREE.ClampToEdgeWrapping;this.mag_filter=g!==undefined?g:THREE.LinearFilter;this.min_filter=f!==undefined?f:THREE.LinearMipMapLinearFilter};
|
|
THREE.Texture.prototype={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.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&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.indexOf(a)===-1&&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+" )"}};
|
|
THREE.Fog=function(a,b,e){this.color=new THREE.Color(a);this.near=b||1;this.far=e||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
|
|
THREE.Projector=function(){function a(n,l){return l.z-n.z}function b(n,l){var s=0,o=1,A=n.z+n.w,G=l.z+l.w,C=-n.z+n.w,H=-l.z+l.w;if(A>=0&&G>=0&&C>=0&&H>=0)return true;else if(A<0&&G<0||C<0&&H<0)return false;else{if(A<0)s=Math.max(s,A/(A-G));else if(G<0)o=Math.min(o,A/(A-G));if(C<0)s=Math.max(s,C/(C-H));else if(H<0)o=Math.min(o,C/(C-H));if(o<s)return false;else{n.lerpSelf(l,s);l.lerpSelf(n,1-o);return true}}}var e,d,g=[],f,k,h,j=[],c,w,B=[],t,u,x=[],z=new THREE.Vector4,L=new THREE.Vector4,v=new THREE.Matrix4,
|
|
E=new THREE.Matrix4,m=[],O=new THREE.Vector4,i=new THREE.Vector4,r;this.projectObjects=function(n,l,s){var o=[],A,G;d=0;v.multiply(l.projectionMatrix,l.matrix);m[0]=new THREE.Vector4(v.n41-v.n11,v.n42-v.n12,v.n43-v.n13,v.n44-v.n14);m[1]=new THREE.Vector4(v.n41+v.n11,v.n42+v.n12,v.n43+v.n13,v.n44+v.n14);m[2]=new THREE.Vector4(v.n41+v.n21,v.n42+v.n22,v.n43+v.n23,v.n44+v.n24);m[3]=new THREE.Vector4(v.n41-v.n21,v.n42-v.n22,v.n43-v.n23,v.n44-v.n24);m[4]=new THREE.Vector4(v.n41-v.n31,v.n42-v.n32,v.n43-
|
|
v.n33,v.n44-v.n34);m[5]=new THREE.Vector4(v.n41+v.n31,v.n42+v.n32,v.n43+v.n33,v.n44+v.n34);l=0;for(A=m.length;l<A;l++){G=m[l];G.divideScalar(Math.sqrt(G.x*G.x+G.y*G.y+G.z*G.z))}A=n.objects;n=0;for(l=A.length;n<l;n++){G=A[n];var C;if(!(C=!G.visible)){if(C=G instanceof THREE.Mesh){a:{C=void 0;for(var H=G.position,V=-G.geometry.boundingSphere.radius*Math.max(G.scale.x,Math.max(G.scale.y,G.scale.z)),D=0;D<6;D++){C=m[D].x*H.x+m[D].y*H.y+m[D].z*H.z+m[D].w;if(C<=V){C=false;break a}}C=true}C=!C}C=C}if(!C){e=
|
|
g[d]=g[d]||new THREE.RenderableObject;z.copy(G.position);v.multiplyVector3(z);e.object=G;e.z=z.z;o.push(e);d++}}s&&o.sort(a);return o};this.projectScene=function(n,l,s){var o=[],A=l.near,G=l.far,C,H,V,D,Q,K,P,W,Y,I,J,T,p,q,y,N;h=w=u=0;l.autoUpdateMatrix&&l.updateMatrix();v.multiply(l.projectionMatrix,l.matrix);K=this.projectObjects(n,l,true);n=0;for(C=K.length;n<C;n++){P=K[n].object;if(P.visible){P.autoUpdateMatrix&&P.updateMatrix();W=P.matrix;Y=P.rotationMatrix;I=P.materials;J=P.overdraw;if(P instanceof
|
|
THREE.Mesh){T=P.geometry;p=T.vertices;H=0;for(V=p.length;H<V;H++){q=p[H];q.positionWorld.copy(q.position);W.multiplyVector3(q.positionWorld);D=q.positionScreen;D.copy(q.positionWorld);v.multiplyVector4(D);D.x/=D.w;D.y/=D.w;q.__visible=D.z>A&&D.z<G}T=T.faces;H=0;for(V=T.length;H<V;H++){q=T[H];if(q instanceof THREE.Face3){D=p[q.a];Q=p[q.b];y=p[q.c];if(D.__visible&&Q.__visible&&y.__visible)if(P.doubleSided||P.flipSided!=(y.positionScreen.x-D.positionScreen.x)*(Q.positionScreen.y-D.positionScreen.y)-
|
|
(y.positionScreen.y-D.positionScreen.y)*(Q.positionScreen.x-D.positionScreen.x)<0){f=j[h]=j[h]||new THREE.RenderableFace3;f.v1.positionWorld.copy(D.positionWorld);f.v2.positionWorld.copy(Q.positionWorld);f.v3.positionWorld.copy(y.positionWorld);f.v1.positionScreen.copy(D.positionScreen);f.v2.positionScreen.copy(Q.positionScreen);f.v3.positionScreen.copy(y.positionScreen);f.normalWorld.copy(q.normal);Y.multiplyVector3(f.normalWorld);f.centroidWorld.copy(q.centroid);W.multiplyVector3(f.centroidWorld);
|
|
f.centroidScreen.copy(f.centroidWorld);v.multiplyVector3(f.centroidScreen);y=q.vertexNormals;r=f.vertexNormalsWorld;D=0;for(Q=y.length;D<Q;D++){N=r[D]=r[D]||new THREE.Vector3;N.copy(y[D]);Y.multiplyVector3(N)}f.z=f.centroidScreen.z;f.meshMaterials=I;f.faceMaterials=q.materials;f.overdraw=J;if(P.geometry.uvs[H]){f.uvs[0]=P.geometry.uvs[H][0];f.uvs[1]=P.geometry.uvs[H][1];f.uvs[2]=P.geometry.uvs[H][2]}o.push(f);h++}}else if(q instanceof THREE.Face4){D=p[q.a];Q=p[q.b];y=p[q.c];N=p[q.d];if(D.__visible&&
|
|
Q.__visible&&y.__visible&&N.__visible)if(P.doubleSided||P.flipSided!=((N.positionScreen.x-D.positionScreen.x)*(Q.positionScreen.y-D.positionScreen.y)-(N.positionScreen.y-D.positionScreen.y)*(Q.positionScreen.x-D.positionScreen.x)<0||(Q.positionScreen.x-y.positionScreen.x)*(N.positionScreen.y-y.positionScreen.y)-(Q.positionScreen.y-y.positionScreen.y)*(N.positionScreen.x-y.positionScreen.x)<0)){f=j[h]=j[h]||new THREE.RenderableFace3;f.v1.positionWorld.copy(D.positionWorld);f.v2.positionWorld.copy(Q.positionWorld);
|
|
f.v3.positionWorld.copy(N.positionWorld);f.v1.positionScreen.copy(D.positionScreen);f.v2.positionScreen.copy(Q.positionScreen);f.v3.positionScreen.copy(N.positionScreen);f.normalWorld.copy(q.normal);Y.multiplyVector3(f.normalWorld);f.centroidWorld.copy(q.centroid);W.multiplyVector3(f.centroidWorld);f.centroidScreen.copy(f.centroidWorld);v.multiplyVector3(f.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterials=I;f.faceMaterials=q.materials;f.overdraw=J;if(P.geometry.uvs[H]){f.uvs[0]=P.geometry.uvs[H][0];
|
|
f.uvs[1]=P.geometry.uvs[H][1];f.uvs[2]=P.geometry.uvs[H][3]}o.push(f);h++;k=j[h]=j[h]||new THREE.RenderableFace3;k.v1.positionWorld.copy(Q.positionWorld);k.v2.positionWorld.copy(y.positionWorld);k.v3.positionWorld.copy(N.positionWorld);k.v1.positionScreen.copy(Q.positionScreen);k.v2.positionScreen.copy(y.positionScreen);k.v3.positionScreen.copy(N.positionScreen);k.normalWorld.copy(f.normalWorld);k.centroidWorld.copy(f.centroidWorld);k.centroidScreen.copy(f.centroidScreen);k.z=k.centroidScreen.z;k.meshMaterials=
|
|
I;k.faceMaterials=q.materials;k.overdraw=J;if(P.geometry.uvs[H]){k.uvs[0]=P.geometry.uvs[H][1];k.uvs[1]=P.geometry.uvs[H][2];k.uvs[2]=P.geometry.uvs[H][3]}o.push(k);h++}}}}else if(P instanceof THREE.Line){E.multiply(v,W);p=P.geometry.vertices;q=p[0];q.positionScreen.copy(q.position);E.multiplyVector4(q.positionScreen);H=1;for(V=p.length;H<V;H++){D=p[H];D.positionScreen.copy(D.position);E.multiplyVector4(D.positionScreen);Q=p[H-1];O.copy(D.positionScreen);i.copy(Q.positionScreen);if(b(O,i)){O.multiplyScalar(1/
|
|
O.w);i.multiplyScalar(1/i.w);c=B[w]=B[w]||new THREE.RenderableLine;c.v1.positionScreen.copy(O);c.v2.positionScreen.copy(i);c.z=Math.max(O.z,i.z);c.materials=P.materials;o.push(c);w++}}}else if(P instanceof THREE.Particle){L.set(P.position.x,P.position.y,P.position.z,1);v.multiplyVector4(L);L.z/=L.w;if(L.z>0&&L.z<1){t=x[u]=x[u]||new THREE.RenderableParticle;t.x=L.x/L.w;t.y=L.y/L.w;t.z=L.z;t.rotation=P.rotation.z;t.scale.x=P.scale.x*Math.abs(t.x-(L.x+l.projectionMatrix.n11)/(L.w+l.projectionMatrix.n14));
|
|
t.scale.y=P.scale.y*Math.abs(t.y-(L.y+l.projectionMatrix.n22)/(L.w+l.projectionMatrix.n24));t.materials=P.materials;o.push(t);u++}}}}s&&o.sort(a);return o};this.unprojectVector=function(n,l){var s=new THREE.Matrix4;s.multiply(THREE.Matrix4.makeInvert(l.matrix),THREE.Matrix4.makeInvert(l.projectionMatrix));s.multiplyVector3(n);return n}};
|
|
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,e,d,g,f;this.domElement=document.createElement("div");this.setSize=function(k,h){e=k;d=h;g=e/2;f=d/2};this.render=function(k,h){var j,c,w,B,t,u,x,z;a=b.projectScene(k,h);j=0;for(c=a.length;j<c;j++){t=a[j];if(t instanceof THREE.RenderableParticle){x=t.x*g+g;z=t.y*f+f;w=0;for(B=t.material.length;w<B;w++){u=t.material[w];if(u instanceof THREE.ParticleDOMMaterial){u=u.domElement;u.style.left=x+"px";u.style.top=z+"px"}}}}}};
|
|
THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,e=document.createElement("canvas"),d,g,f,k,h=e.getContext("2d"),j=1,c=0,w=null,B=null,t=1,u,x,z,L,v,E,m,O,i,r=new THREE.Color,n=new THREE.Color,l=new THREE.Color,s=new THREE.Color,o=new THREE.Color,A,G,C,H,V,D,Q,K,P,W=new THREE.Rectangle,Y=new THREE.Rectangle,I=new THREE.Rectangle,J=false,T=new THREE.Color,p=new THREE.Color,q=new THREE.Color,y=new THREE.Color,N=Math.PI*2,R=new THREE.Vector3,ba,fa,na,da,ra,va,oa=16;ba=document.createElement("canvas");
|
|
ba.width=ba.height=2;fa=ba.getContext("2d");fa.fillStyle="rgba(0,0,0,1)";fa.fillRect(0,0,2,2);na=fa.getImageData(0,0,2,2);da=na.data;ra=document.createElement("canvas");ra.width=ra.height=oa;va=ra.getContext("2d");va.translate(-oa/2,-oa/2);va.scale(oa,oa);oa--;this.domElement=e;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ia,pa){d=ia;g=pa;f=d/2;k=g/2;e.width=d;e.height=g;W.set(-f,-k,f,k)};this.clear=function(){if(!Y.isEmpty()){Y.inflate(1);Y.minSelf(W);h.clearRect(Y.getX(),
|
|
Y.getY(),Y.getWidth(),Y.getHeight());Y.empty()}};this.render=function(ia,pa){function Ka(F){var X,U,M,S=F.lights;p.setRGB(0,0,0);q.setRGB(0,0,0);y.setRGB(0,0,0);F=0;for(X=S.length;F<X;F++){U=S[F];M=U.color;if(U instanceof THREE.AmbientLight){p.r+=M.r;p.g+=M.g;p.b+=M.b}else if(U instanceof THREE.DirectionalLight){q.r+=M.r;q.g+=M.g;q.b+=M.b}else if(U instanceof THREE.PointLight){y.r+=M.r;y.g+=M.g;y.b+=M.b}}}function wa(F,X,U,M){var S,Z,aa,ca,ea=F.lights;F=0;for(S=ea.length;F<S;F++){Z=ea[F];aa=Z.color;
|
|
ca=Z.intensity;if(Z instanceof THREE.DirectionalLight){Z=U.dot(Z.position)*ca;if(Z>0){M.r+=aa.r*Z;M.g+=aa.g*Z;M.b+=aa.b*Z}}else if(Z instanceof THREE.PointLight){R.sub(Z.position,X);R.normalize();Z=U.dot(R)*ca;if(Z>0){M.r+=aa.r*Z;M.g+=aa.g*Z;M.b+=aa.b*Z}}}}function La(F,X,U){if(U.opacity!=0){Ba(U.opacity);xa(U.blending);var M,S,Z,aa,ca,ea;if(U instanceof THREE.ParticleBasicMaterial){if(U.map){aa=U.map;ca=aa.width>>1;ea=aa.height>>1;S=X.scale.x*f;Z=X.scale.y*k;U=S*ca;M=Z*ea;I.set(F.x-U,F.y-M,F.x+U,
|
|
F.y+M);if(W.instersects(I)){h.save();h.translate(F.x,F.y);h.rotate(-X.rotation);h.scale(S,-Z);h.translate(-ca,-ea);h.drawImage(aa,0,0);h.restore()}}}else if(U instanceof THREE.ParticleCircleMaterial){if(J){T.r=p.r+q.r+y.r;T.g=p.g+q.g+y.g;T.b=p.b+q.b+y.b;r.r=U.color.r*T.r;r.g=U.color.g*T.g;r.b=U.color.b*T.b;r.updateStyleString()}else r.__styleString=U.color.__styleString;U=X.scale.x*f;M=X.scale.y*k;I.set(F.x-U,F.y-M,F.x+U,F.y+M);if(W.instersects(I)){S=r.__styleString;if(B!=S)h.fillStyle=B=S;h.save();
|
|
h.translate(F.x,F.y);h.rotate(-X.rotation);h.scale(U,M);h.beginPath();h.arc(0,0,1,0,N,true);h.closePath();h.fill();h.restore()}}}}function Ma(F,X,U,M){if(M.opacity!=0){Ba(M.opacity);xa(M.blending);h.beginPath();h.moveTo(F.positionScreen.x,F.positionScreen.y);h.lineTo(X.positionScreen.x,X.positionScreen.y);h.closePath();if(M instanceof THREE.LineBasicMaterial){r.__styleString=M.color.__styleString;F=M.linewidth;if(t!=F)h.lineWidth=t=F;F=r.__styleString;if(w!=F)h.strokeStyle=w=F;h.stroke();I.inflate(M.linewidth*
|
|
2)}}}function Ga(F,X,U,M,S,Z){if(S.opacity!=0){Ba(S.opacity);xa(S.blending);L=F.positionScreen.x;v=F.positionScreen.y;E=X.positionScreen.x;m=X.positionScreen.y;O=U.positionScreen.x;i=U.positionScreen.y;h.beginPath();h.moveTo(L,v);h.lineTo(E,m);h.lineTo(O,i);h.lineTo(L,v);h.closePath();if(S instanceof THREE.MeshBasicMaterial)if(S.map)S.map.image.loaded&&S.map.mapping instanceof THREE.UVMapping&&sa(L,v,E,m,O,i,S.map.image,M.uvs[0].u,M.uvs[0].v,M.uvs[1].u,M.uvs[1].v,M.uvs[2].u,M.uvs[2].v);else if(S.env_map){if(S.env_map.image.loaded)if(S.env_map.mapping instanceof
|
|
THREE.SphericalReflectionMapping){F=pa.matrix;R.copy(M.vertexNormalsWorld[0]);H=(R.x*F.n11+R.y*F.n12+R.z*F.n13)*0.5+0.5;V=-(R.x*F.n21+R.y*F.n22+R.z*F.n23)*0.5+0.5;R.copy(M.vertexNormalsWorld[1]);D=(R.x*F.n11+R.y*F.n12+R.z*F.n13)*0.5+0.5;Q=-(R.x*F.n21+R.y*F.n22+R.z*F.n23)*0.5+0.5;R.copy(M.vertexNormalsWorld[2]);K=(R.x*F.n11+R.y*F.n12+R.z*F.n13)*0.5+0.5;P=-(R.x*F.n21+R.y*F.n22+R.z*F.n23)*0.5+0.5;sa(L,v,E,m,O,i,S.env_map.image,H,V,D,Q,K,P)}}else S.wireframe?ya(S.color.__styleString,S.wireframe_linewidth):
|
|
za(S.color.__styleString);else if(S instanceof THREE.MeshLambertMaterial){if(S.map&&!S.wireframe){S.map.mapping instanceof THREE.UVMapping&&sa(L,v,E,m,O,i,S.map.image,M.uvs[0].u,M.uvs[0].v,M.uvs[1].u,M.uvs[1].v,M.uvs[2].u,M.uvs[2].v);xa(THREE.SubtractiveBlending)}if(J)if(!S.wireframe&&S.shading==THREE.SmoothShading&&M.vertexNormalsWorld.length==3){n.r=l.r=s.r=p.r;n.g=l.g=s.g=p.g;n.b=l.b=s.b=p.b;wa(Z,M.v1.positionWorld,M.vertexNormalsWorld[0],n);wa(Z,M.v2.positionWorld,M.vertexNormalsWorld[1],l);wa(Z,
|
|
M.v3.positionWorld,M.vertexNormalsWorld[2],s);o.r=(l.r+s.r)*0.5;o.g=(l.g+s.g)*0.5;o.b=(l.b+s.b)*0.5;C=Ha(n,l,s,o);sa(L,v,E,m,O,i,C,0,0,1,0,0,1)}else{T.r=p.r;T.g=p.g;T.b=p.b;wa(Z,M.centroidWorld,M.normalWorld,T);r.r=S.color.r*T.r;r.g=S.color.g*T.g;r.b=S.color.b*T.b;r.updateStyleString();S.wireframe?ya(r.__styleString,S.wireframe_linewidth):za(r.__styleString)}else S.wireframe?ya(S.color.__styleString,S.wireframe_linewidth):za(S.color.__styleString)}else if(S instanceof THREE.MeshDepthMaterial){A=pa.near;
|
|
G=pa.far;n.r=n.g=n.b=1-Ca(F.positionScreen.z,A,G);l.r=l.g=l.b=1-Ca(X.positionScreen.z,A,G);s.r=s.g=s.b=1-Ca(U.positionScreen.z,A,G);o.r=(l.r+s.r)*0.5;o.g=(l.g+s.g)*0.5;o.b=(l.b+s.b)*0.5;C=Ha(n,l,s,o);sa(L,v,E,m,O,i,C,0,0,1,0,0,1)}else if(S instanceof THREE.MeshNormalMaterial){r.r=Da(M.normalWorld.x);r.g=Da(M.normalWorld.y);r.b=Da(M.normalWorld.z);r.updateStyleString();S.wireframe?ya(r.__styleString,S.wireframe_linewidth):za(r.__styleString)}}}function ya(F,X){if(w!=F)h.strokeStyle=w=F;if(t!=X)h.lineWidth=
|
|
t=X;h.stroke();I.inflate(X*2)}function za(F){if(B!=F)h.fillStyle=B=F;h.fill()}function sa(F,X,U,M,S,Z,aa,ca,ea,ja,ga,ka,ta){var ma,la;ma=aa.width-1;la=aa.height-1;ca*=ma;ea*=la;ja*=ma;ga*=la;ka*=ma;ta*=la;U-=F;M-=X;S-=F;Z-=X;ja-=ca;ga-=ea;ka-=ca;ta-=ea;la=1/(ja*ta-ka*ga);ma=(ta*U-ga*S)*la;ga=(ta*M-ga*Z)*la;U=(ja*S-ka*U)*la;M=(ja*Z-ka*M)*la;F=F-ma*ca-U*ea;X=X-ga*ca-M*ea;h.save();h.transform(ma,ga,U,M,F,X);h.clip();h.drawImage(aa,0,0);h.restore()}function Ba(F){if(j!=F)h.globalAlpha=j=F}function xa(F){if(c!=
|
|
F){switch(F){case THREE.NormalBlending:h.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:h.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:h.globalCompositeOperation="darker"}c=F}}function Ha(F,X,U,M){var S=~~(F.r*255),Z=~~(F.g*255);F=~~(F.b*255);var aa=~~(X.r*255),ca=~~(X.g*255);X=~~(X.b*255);var ea=~~(U.r*255),ja=~~(U.g*255);U=~~(U.b*255);var ga=~~(M.r*255),ka=~~(M.g*255);M=~~(M.b*255);da[0]=S<0?0:S>255?255:S;da[1]=Z<0?0:Z>255?255:Z;da[2]=F<0?0:F>
|
|
255?255:F;da[4]=aa<0?0:aa>255?255:aa;da[5]=ca<0?0:ca>255?255:ca;da[6]=X<0?0:X>255?255:X;da[8]=ea<0?0:ea>255?255:ea;da[9]=ja<0?0:ja>255?255:ja;da[10]=U<0?0:U>255?255:U;da[12]=ga<0?0:ga>255?255:ga;da[13]=ka<0?0:ka>255?255:ka;da[14]=M<0?0:M>255?255:M;fa.putImageData(na,0,0);va.drawImage(ba,0,0);return ra}function Ca(F,X,U){F=(F-X)/(U-X);return F*F*(3-2*F)}function Da(F){F=(F+1)*0.5;return F<0?0:F>1?1:F}function Ea(F,X){var U=X.x-F.x,M=X.y-F.y,S=1/Math.sqrt(U*U+M*M);U*=S;M*=S;X.x+=U;X.y+=M;F.x-=U;F.y-=
|
|
M}var Aa,Ia,$,ha,qa,Fa,Ja,ua;h.setTransform(1,0,0,-1,f,k);this.autoClear&&this.clear();a=b.projectScene(ia,pa,this.sortElements);(J=ia.lights.length>0)&&Ka(ia);Aa=0;for(Ia=a.length;Aa<Ia;Aa++){$=a[Aa];I.empty();if($ instanceof THREE.RenderableParticle){u=$;u.x*=f;u.y*=k;ha=0;for(qa=$.materials.length;ha<qa;ha++)La(u,$,$.materials[ha],ia)}else if($ instanceof THREE.RenderableLine){u=$.v1;x=$.v2;u.positionScreen.x*=f;u.positionScreen.y*=k;x.positionScreen.x*=f;x.positionScreen.y*=k;I.addPoint(u.positionScreen.x,
|
|
u.positionScreen.y);I.addPoint(x.positionScreen.x,x.positionScreen.y);if(W.instersects(I)){ha=0;for(qa=$.materials.length;ha<qa;)Ma(u,x,$,$.materials[ha++],ia)}}else if($ instanceof THREE.RenderableFace3){u=$.v1;x=$.v2;z=$.v3;u.positionScreen.x*=f;u.positionScreen.y*=k;x.positionScreen.x*=f;x.positionScreen.y*=k;z.positionScreen.x*=f;z.positionScreen.y*=k;if($.overdraw){Ea(u.positionScreen,x.positionScreen);Ea(x.positionScreen,z.positionScreen);Ea(z.positionScreen,u.positionScreen)}I.add3Points(u.positionScreen.x,
|
|
u.positionScreen.y,x.positionScreen.x,x.positionScreen.y,z.positionScreen.x,z.positionScreen.y);if(W.instersects(I)){ha=0;for(qa=$.meshMaterials.length;ha<qa;){ua=$.meshMaterials[ha++];if(ua instanceof THREE.MeshFaceMaterial){Fa=0;for(Ja=$.faceMaterials.length;Fa<Ja;)(ua=$.faceMaterials[Fa++])&&Ga(u,x,z,$,ua,ia)}else Ga(u,x,z,$,ua,ia)}}}Y.addRectangle(I)}h.setTransform(1,0,0,1,0,0)}};
|
|
THREE.SVGRenderer=function(){function a(K,P,W){var Y,I,J,T;Y=0;for(I=K.lights.length;Y<I;Y++){J=K.lights[Y];if(J instanceof THREE.DirectionalLight){T=P.normalWorld.dot(J.position)*J.intensity;if(T>0){W.r+=J.color.r*T;W.g+=J.color.g*T;W.b+=J.color.b*T}}else if(J instanceof THREE.PointLight){s.sub(J.position,P.centroidWorld);s.normalize();T=P.normalWorld.dot(s)*J.intensity;if(T>0){W.r+=J.color.r*T;W.g+=J.color.g*T;W.b+=J.color.b*T}}}}function b(K,P,W,Y,I,J){C=d(H++);C.setAttribute("d","M "+K.positionScreen.x+
|
|
" "+K.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+"z");if(I instanceof THREE.MeshBasicMaterial)m.__styleString=I.color.__styleString;else if(I instanceof THREE.MeshLambertMaterial)if(E){O.r=i.r;O.g=i.g;O.b=i.b;a(J,Y,O);m.r=I.color.r*O.r;m.g=I.color.g*O.g;m.b=I.color.b*O.b;m.updateStyleString()}else m.__styleString=I.color.__styleString;else if(I instanceof THREE.MeshDepthMaterial){l=1-I.__2near/(I.__farPlusNear-Y.z*I.__farMinusNear);
|
|
m.setRGB(l,l,l)}else I instanceof THREE.MeshNormalMaterial&&m.setRGB(g(Y.normalWorld.x),g(Y.normalWorld.y),g(Y.normalWorld.z));I.wireframe?C.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+I.wireframe_linewidth+"; stroke-opacity: "+I.opacity+"; stroke-linecap: "+I.wireframe_linecap+"; stroke-linejoin: "+I.wireframe_linejoin):C.setAttribute("style","fill: "+m.__styleString+"; fill-opacity: "+I.opacity);h.appendChild(C)}function e(K,P,W,Y,I,J,T){C=d(H++);C.setAttribute("d",
|
|
"M "+K.positionScreen.x+" "+K.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+" L "+Y.positionScreen.x+","+Y.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)m.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(E){O.r=i.r;O.g=i.g;O.b=i.b;a(T,I,O);m.r=J.color.r*O.r;m.g=J.color.g*O.g;m.b=J.color.b*O.b;m.updateStyleString()}else m.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){l=
|
|
1-J.__2near/(J.__farPlusNear-I.z*J.__farMinusNear);m.setRGB(l,l,l)}else J instanceof THREE.MeshNormalMaterial&&m.setRGB(g(I.normalWorld.x),g(I.normalWorld.y),g(I.normalWorld.z));J.wireframe?C.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):C.setAttribute("style","fill: "+m.__styleString+"; fill-opacity: "+J.opacity);h.appendChild(C)}
|
|
function d(K){if(o[K]==null){o[K]=document.createElementNS("http://www.w3.org/2000/svg","path");Q==0&&o[K].setAttribute("shape-rendering","crispEdges");return o[K]}return o[K]}function g(K){return K<0?Math.min((1+K)*0.5,0.5):0.5+Math.min(K*0.5,0.5)}var f=null,k=new THREE.Projector,h=document.createElementNS("http://www.w3.org/2000/svg","svg"),j,c,w,B,t,u,x,z,L=new THREE.Rectangle,v=new THREE.Rectangle,E=false,m=new THREE.Color(16777215),O=new THREE.Color(16777215),i=new THREE.Color(0),r=new THREE.Color(0),
|
|
n=new THREE.Color(0),l,s=new THREE.Vector3,o=[],A=[],G=[],C,H,V,D,Q=1;this.domElement=h;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(K){switch(K){case "high":Q=1;break;case "low":Q=0}};this.setSize=function(K,P){j=K;c=P;w=j/2;B=c/2;h.setAttribute("viewBox",-w+" "+-B+" "+j+" "+c);h.setAttribute("width",j);h.setAttribute("height",c);L.set(-w,-B,w,B)};this.clear=function(){for(;h.childNodes.length>0;)h.removeChild(h.childNodes[0])};this.render=function(K,P){var W,Y,
|
|
I,J,T,p,q,y;this.autoClear&&this.clear();f=k.projectScene(K,P,this.sortElements);D=V=H=0;if(E=K.lights.length>0){q=K.lights;i.setRGB(0,0,0);r.setRGB(0,0,0);n.setRGB(0,0,0);W=0;for(Y=q.length;W<Y;W++){I=q[W];J=I.color;if(I instanceof THREE.AmbientLight){i.r+=J.r;i.g+=J.g;i.b+=J.b}else if(I instanceof THREE.DirectionalLight){r.r+=J.r;r.g+=J.g;r.b+=J.b}else if(I instanceof THREE.PointLight){n.r+=J.r;n.g+=J.g;n.b+=J.b}}}W=0;for(Y=f.length;W<Y;W++){q=f[W];v.empty();if(q instanceof THREE.RenderableParticle){t=
|
|
q;t.x*=w;t.y*=-B;I=0;for(J=q.materials.length;I<J;I++)if(y=q.materials[I]){T=t;p=q;y=y;var N=V++;if(A[N]==null){A[N]=document.createElementNS("http://www.w3.org/2000/svg","circle");Q==0&&A[N].setAttribute("shape-rendering","crispEdges")}C=A[N];C.setAttribute("cx",T.x);C.setAttribute("cy",T.y);C.setAttribute("r",p.scale.x*w);if(y instanceof THREE.ParticleCircleMaterial){if(E){O.r=i.r+r.r+n.r;O.g=i.g+r.g+n.g;O.b=i.b+r.b+n.b;m.r=y.color.r*O.r;m.g=y.color.g*O.g;m.b=y.color.b*O.b;m.updateStyleString()}else m=
|
|
y.color;C.setAttribute("style","fill: "+m.__styleString)}h.appendChild(C)}}else if(q instanceof THREE.RenderableLine){t=q.v1;u=q.v2;t.positionScreen.x*=w;t.positionScreen.y*=-B;u.positionScreen.x*=w;u.positionScreen.y*=-B;v.addPoint(t.positionScreen.x,t.positionScreen.y);v.addPoint(u.positionScreen.x,u.positionScreen.y);if(L.instersects(v)){I=0;for(J=q.materials.length;I<J;)if(y=q.materials[I++]){T=t;p=u;y=y;N=D++;if(G[N]==null){G[N]=document.createElementNS("http://www.w3.org/2000/svg","line");Q==
|
|
0&&G[N].setAttribute("shape-rendering","crispEdges")}C=G[N];C.setAttribute("x1",T.positionScreen.x);C.setAttribute("y1",T.positionScreen.y);C.setAttribute("x2",p.positionScreen.x);C.setAttribute("y2",p.positionScreen.y);if(y instanceof THREE.LineBasicMaterial){m.__styleString=y.color.__styleString;C.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+y.linewidth+"; stroke-opacity: "+y.opacity+"; stroke-linecap: "+y.linecap+"; stroke-linejoin: "+y.linejoin);h.appendChild(C)}}}}else if(q instanceof
|
|
THREE.RenderableFace3){t=q.v1;u=q.v2;x=q.v3;t.positionScreen.x*=w;t.positionScreen.y*=-B;u.positionScreen.x*=w;u.positionScreen.y*=-B;x.positionScreen.x*=w;x.positionScreen.y*=-B;v.addPoint(t.positionScreen.x,t.positionScreen.y);v.addPoint(u.positionScreen.x,u.positionScreen.y);v.addPoint(x.positionScreen.x,x.positionScreen.y);if(L.instersects(v)){I=0;for(J=q.meshMaterials.length;I<J;){y=q.meshMaterials[I++];if(y instanceof THREE.MeshFaceMaterial){T=0;for(p=q.faceMaterials.length;T<p;)(y=q.faceMaterials[T++])&&
|
|
b(t,u,x,q,y,K)}else y&&b(t,u,x,q,y,K)}}}else if(q instanceof THREE.RenderableFace4){t=q.v1;u=q.v2;x=q.v3;z=q.v4;t.positionScreen.x*=w;t.positionScreen.y*=-B;u.positionScreen.x*=w;u.positionScreen.y*=-B;x.positionScreen.x*=w;x.positionScreen.y*=-B;z.positionScreen.x*=w;z.positionScreen.y*=-B;v.addPoint(t.positionScreen.x,t.positionScreen.y);v.addPoint(u.positionScreen.x,u.positionScreen.y);v.addPoint(x.positionScreen.x,x.positionScreen.y);v.addPoint(z.positionScreen.x,z.positionScreen.y);if(L.instersects(v)){I=
|
|
0;for(J=q.meshMaterials.length;I<J;){y=q.meshMaterials[I++];if(y instanceof THREE.MeshFaceMaterial){T=0;for(p=q.faceMaterials.length;T<p;)(y=q.faceMaterials[T++])&&e(t,u,x,z,q,y,K)}else y&&e(t,u,x,z,q,y,K)}}}}}};
|
|
THREE.WebGLRenderer=function(a){function b(i,r,n){var l=c.createProgram();n=["#ifdef GL_ES\nprecision highp float;\n#endif",n?"#define USE_FOG":"",n instanceof THREE.FogExp2?"#define FOG_EXP2":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");var s=[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(l,k("fragment",n+i));c.attachShader(l,k("vertex",s+r));c.linkProgram(l);c.getProgramParameter(l,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(l,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");l.uniforms={};l.attributes={};return l}function e(i,r){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 n=0;n<6;++n)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,i.image[n]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);i.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+
|
|
r);c.bindTexture(c.TEXTURE_CUBE_MAP,i.image.__webGLTextureCube)}}function d(i,r){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,h(i.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,h(i.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,h(i.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,
|
|
h(i.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+r);c.bindTexture(c.TEXTURE_2D,i.__webGLTexture)}function g(i,r){var n,l,s;n=0;for(l=r.length;n<l;n++){s=r[n];i.uniforms[s]=c.getUniformLocation(i,s)}}function f(i,r){var n,l,s;n=0;for(l=r.length;n<l;n++){s=r[n];i.attributes[s]=c.getAttribLocation(i,s)}}function k(i,r){var n;if(i=="fragment")n=c.createShader(c.FRAGMENT_SHADER);else if(i=="vertex")n=c.createShader(c.VERTEX_SHADER);c.shaderSource(n,
|
|
r);c.compileShader(n);if(!c.getShaderParameter(n,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(n));return null}return n}function h(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,w,B,t=new THREE.Matrix4,u,x=new Float32Array(16),z=new Float32Array(16),L=new Float32Array(16),v=new Float32Array(9),E=new Float32Array(16),m=function(i,r){if(i){var n,l,s,o=pointLights=maxDirLights=maxPointLights=0;n=0;for(l=i.lights.length;n<l;n++){s=i.lights[n];s instanceof THREE.DirectionalLight&&o++;s instanceof
|
|
THREE.PointLight&&pointLights++}if(pointLights+o<=r){maxDirLights=o;maxPointLights=pointLights}else{maxDirLights=Math.ceil(r*o/(pointLights+o));maxPointLights=r-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:r-1}}(a.scene,4);fog=a.scene?a.scene.fog:null;antialias=a.antialias!=undefined?a.antialias:true;clearColor=a.clearColor?new THREE.Color(a.clearColor):new THREE.Color(0);clearAlpha=a.clearAlpha?a.clearAlpha:0;this.domElement=j;this.autoClear=true;
|
|
(function(i,r,n){try{c=j.getContext("experimental-webgl",{antialias:i})}catch(l){}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(r.r,r.g,r.b,n)})(antialias,clearColor,clearAlpha);w=B=function(i,r,n){var l=[i?"#define MAX_DIR_LIGHTS "+i:"",r?"#define MAX_POINT_LIGHTS "+
|
|
r:"","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 ];":"",r?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",r?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",r?"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;",
|
|
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?"}":"",r?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",r?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",r?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
|
"",r?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",r?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",r?"}":"","}\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"),
|
|
s=[i?"#define MAX_DIR_LIGHTS "+i:"",r?"#define MAX_POINT_LIGHTS "+r:"","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;\n#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
|
i?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",r?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\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 == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
|
|
r?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",r?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",r?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",r?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",r?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",r?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",r?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",r?"float pointSpecularWeight = 0.0;":"",r?"if ( pointDotNormalHalf >= 0.0 )":
|
|
"",r?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",r?"pointDiffuse += mColor * pointDiffuseWeight;":"",r?"pointSpecular += mSpecular * pointSpecularWeight;":"",r?"}":"",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;":"",r?"totalLight += pointDiffuse + pointSpecular;":
|
|
"","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#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif\n}"].join("\n");
|
|
l=b(s,l,n);c.useProgram(l);g(l,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);n&&g(l,["fogColor","fogNear","fogFar","fogDensity"]);i&&g(l,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);r&&g(l,["pointLightNumber",
|
|
"pointLightColor","pointLightPosition"]);c.uniform1i(l.uniforms.enableMap,0);c.uniform1i(l.uniforms.tMap,0);c.uniform1i(l.uniforms.enableCubeMap,0);c.uniform1i(l.uniforms.tCube,1);c.uniform1i(l.uniforms.mixEnvMap,0);c.uniform1i(l.uniforms.useRefract,0);f(l,["position","normal","uv"]);return l}(m.directional,m.point,fog);this.setSize=function(i,r){j.width=i;j.height=r;c.viewport(0,0,j.width,j.height)};this.setClearColor=function(i,r){var n=new THREE.Color(i);c.clearColor(n.r,n.g,n.b,r)};this.clear=
|
|
function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(i,r){var n,l,s,o,A,G=[],C=[],H=[];o=[];A=[];c.uniform1i(i.uniforms.enableLighting,r.length);n=0;for(l=r.length;n<l;n++){s=r[n];if(s instanceof THREE.AmbientLight)G.push(s);else if(s instanceof THREE.DirectionalLight)H.push(s);else s instanceof THREE.PointLight&&C.push(s)}n=s=o=A=0;for(l=G.length;n<l;n++){s+=G[n].color.r;o+=G[n].color.g;A+=G[n].color.b}c.uniform3f(i.uniforms.ambientLightColor,s,o,A);o=[];A=[];n=0;
|
|
for(l=H.length;n<l;n++){s=H[n];o.push(s.color.r*s.intensity);o.push(s.color.g*s.intensity);o.push(s.color.b*s.intensity);A.push(s.position.x);A.push(s.position.y);A.push(s.position.z)}if(H.length){c.uniform1i(i.uniforms.directionalLightNumber,H.length);c.uniform3fv(i.uniforms.directionalLightDirection,A);c.uniform3fv(i.uniforms.directionalLightColor,o)}o=[];A=[];n=0;for(l=C.length;n<l;n++){s=C[n];o.push(s.color.r*s.intensity);o.push(s.color.g*s.intensity);o.push(s.color.b*s.intensity);A.push(s.position.x);
|
|
A.push(s.position.y);A.push(s.position.z)}if(C.length){c.uniform1i(i.uniforms.pointLightNumber,C.length);c.uniform3fv(i.uniforms.pointLightPosition,A);c.uniform3fv(i.uniforms.pointLightColor,o)}};this.createBuffers=function(i,r){var n,l,s,o,A,G,C,H,V,D=[],Q=[],K=[],P=[],W=[],Y=[],I=0,J=i.geometry.geometryChunks[r],T;s=false;n=0;for(l=i.materials.length;n<l;n++){meshMaterial=i.materials[n];if(meshMaterial instanceof THREE.MeshFaceMaterial){A=0;for(T=J.materials.length;A<T;A++)if(J.materials[A]&&J.materials[A].shading!=
|
|
undefined&&J.materials[A].shading==THREE.SmoothShading){s=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){s=true;break}if(s)break}T=s;n=0;for(l=J.faces.length;n<l;n++){s=J.faces[n];o=i.geometry.faces[s];A=o.vertexNormals;faceNormal=o.normal;s=i.geometry.uvs[s];if(o instanceof THREE.Face3){G=i.geometry.vertices[o.a].position;C=i.geometry.vertices[o.b].position;H=i.geometry.vertices[o.c].position;K.push(G.x,G.y,G.z);K.push(C.x,C.y,C.z);K.push(H.x,
|
|
H.y,H.z);if(i.geometry.hasTangents){G=i.geometry.vertices[o.a].tangent;C=i.geometry.vertices[o.b].tangent;H=i.geometry.vertices[o.c].tangent;W.push(G.x,G.y,G.z,G.w);W.push(C.x,C.y,C.z,C.w);W.push(H.x,H.y,H.z,H.w)}if(A.length==3&&T)for(o=0;o<3;o++)P.push(A[o].x,A[o].y,A[o].z);else for(o=0;o<3;o++)P.push(faceNormal.x,faceNormal.y,faceNormal.z);if(s)for(o=0;o<3;o++)Y.push(s[o].u,s[o].v);D.push(I,I+1,I+2);Q.push(I,I+1);Q.push(I,I+2);Q.push(I+1,I+2);I+=3}else if(o instanceof THREE.Face4){G=i.geometry.vertices[o.a].position;
|
|
C=i.geometry.vertices[o.b].position;H=i.geometry.vertices[o.c].position;V=i.geometry.vertices[o.d].position;K.push(G.x,G.y,G.z);K.push(C.x,C.y,C.z);K.push(H.x,H.y,H.z);K.push(V.x,V.y,V.z);if(i.geometry.hasTangents){G=i.geometry.vertices[o.a].tangent;C=i.geometry.vertices[o.b].tangent;H=i.geometry.vertices[o.c].tangent;o=i.geometry.vertices[o.d].tangent;W.push(G.x,G.y,G.z,G.w);W.push(C.x,C.y,C.z,C.w);W.push(H.x,H.y,H.z,H.w);W.push(o.x,o.y,o.z,o.w)}if(A.length==4&&T)for(o=0;o<4;o++)P.push(A[o].x,A[o].y,
|
|
A[o].z);else for(o=0;o<4;o++)P.push(faceNormal.x,faceNormal.y,faceNormal.z);if(s)for(o=0;o<4;o++)Y.push(s[o].u,s[o].v);D.push(I,I+1,I+2);D.push(I,I+2,I+3);Q.push(I,I+1);Q.push(I,I+2);Q.push(I,I+3);Q.push(I+1,I+2);Q.push(I+2,I+3);I+=4}}if(K.length){J.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,J.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(K),c.STATIC_DRAW);J.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,J.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,
|
|
new Float32Array(P),c.STATIC_DRAW);if(i.geometry.hasTangents){J.__webGLTangentBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,J.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(W),c.STATIC_DRAW)}if(Y.length>0){J.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,J.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(Y),c.STATIC_DRAW)}J.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,J.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,
|
|
new Uint16Array(D),c.STATIC_DRAW);J.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,J.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);J.__webGLFaceCount=D.length;J.__webGLLineCount=Q.length}};this.renderBuffer=function(i,r,n,l,s){var o,A,G,C,H,V,D,Q,K;if(l instanceof THREE.MeshShaderMaterial||l instanceof THREE.MeshDepthMaterial||l instanceof THREE.MeshNormalMaterial){if(!l.program){if(l instanceof THREE.MeshDepthMaterial){D=O.depth;
|
|
l.fragment_shader=D.fragment_shader;l.vertex_shader=D.vertex_shader;l.uniforms=D.uniforms;l.uniforms.mNear.value=i.near;l.uniforms.mFar.value=i.far}else if(l instanceof THREE.MeshNormalMaterial){D=O.normal;l.fragment_shader=D.fragment_shader;l.vertex_shader=D.vertex_shader;l.uniforms=D.uniforms}l.program=b(l.fragment_shader,l.vertex_shader,null);D=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(K in l.uniforms)D.push(K);g(l.program,D);f(l.program,
|
|
["position","normal","uv","tangent"])}K=l.program}else K=B;if(K!=w){c.useProgram(K);w=K}K==B&&this.setupLights(K,r);this.loadCamera(K,i);this.loadMatrices(K);if(l instanceof THREE.MeshShaderMaterial||l instanceof THREE.MeshDepthMaterial||l instanceof THREE.MeshNormalMaterial){G=l.wireframe;C=l.wireframe_linewidth;i=K;r=l.uniforms;var P;for(o in r){Q=r[o].type;D=r[o].value;P=i.uniforms[o];if(Q=="i")c.uniform1i(P,D);else if(Q=="f")c.uniform1f(P,D);else if(Q=="v3")c.uniform3f(P,D.x,D.y,D.z);else if(Q==
|
|
"c")c.uniform3f(P,D.r,D.g,D.b);else if(Q=="t"){c.uniform1i(P,D);if(Q=r[o].texture)Q.image instanceof Array&&Q.image.length==6?e(Q,D):d(Q,D)}}}if(l instanceof THREE.MeshPhongMaterial||l instanceof THREE.MeshLambertMaterial||l instanceof THREE.MeshBasicMaterial){o=l.color;A=l.opacity;G=l.wireframe;C=l.wireframe_linewidth;H=l.map;V=l.env_map;r=l.combine==THREE.MixOperation;i=l.reflectivity;Q=l.env_map&&l.env_map.mapping instanceof THREE.CubeRefractionMapping;D=l.refraction_ratio;c.uniform4f(K.uniforms.mColor,
|
|
o.r*A,o.g*A,o.b*A,A);c.uniform1i(K.uniforms.mixEnvMap,r);c.uniform1f(K.uniforms.mReflectivity,i);c.uniform1i(K.uniforms.useRefract,Q);c.uniform1f(K.uniforms.mRefractionRatio,D);if(n){c.uniform3f(K.uniforms.fogColor,n.color.r,n.color.g,n.color.b);if(n instanceof THREE.Fog){c.uniform1f(K.uniforms.fogNear,n.near);c.uniform1f(K.uniforms.fogFar,n.far)}else n instanceof THREE.FogExp2&&c.uniform1f(K.uniforms.fogDensity,n.density)}}if(l instanceof THREE.MeshPhongMaterial){n=l.ambient;o=l.specular;l=l.shininess;
|
|
c.uniform4f(K.uniforms.mAmbient,n.r,n.g,n.b,A);c.uniform4f(K.uniforms.mSpecular,o.r,o.g,o.b,A);c.uniform1f(K.uniforms.mShininess,l);c.uniform1i(K.uniforms.material,2)}else if(l instanceof THREE.MeshLambertMaterial)c.uniform1i(K.uniforms.material,1);else l instanceof THREE.MeshBasicMaterial&&c.uniform1i(K.uniforms.material,0);if(H){d(H,0);c.uniform1i(K.uniforms.tMap,0);c.uniform1i(K.uniforms.enableMap,1)}else c.uniform1i(K.uniforms.enableMap,0);if(V){e(V,1);c.uniform1i(K.uniforms.tCube,1);c.uniform1i(K.uniforms.enableCubeMap,
|
|
1)}else c.uniform1i(K.uniforms.enableCubeMap,0);A=K.attributes;c.bindBuffer(c.ARRAY_BUFFER,s.__webGLVertexBuffer);c.vertexAttribPointer(A.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(A.position);if(A.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,s.__webGLNormalBuffer);c.vertexAttribPointer(A.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(A.normal)}if(A.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,s.__webGLTangentBuffer);c.vertexAttribPointer(A.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(A.tangent)}if(A.uv>=
|
|
0)if(s.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,s.__webGLUVBuffer);c.vertexAttribPointer(A.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(A.uv)}else c.disableVertexAttribArray(A.uv);if(G){c.lineWidth(C);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,s.__webGLLineBuffer);c.drawElements(c.LINES,s.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,s.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,s.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(i,r,n,l,s,o,A){var G,
|
|
C,H,V,D;H=0;for(V=l.materials.length;H<V;H++){G=l.materials[H];if(G instanceof THREE.MeshFaceMaterial){G=0;for(C=s.materials.length;G<C;G++)if((D=s.materials[G])&&D.blending==o&&D.opacity<1==A){this.setBlending(D.blending);this.renderBuffer(i,r,n,D,s)}}else if((D=G)&&D.blending==o&&D.opacity<1==A){this.setBlending(D.blending);this.renderBuffer(i,r,n,D,s)}}};this.render=function(i,r){var n,l,s,o,A=i.lights,G=i.fog;this.initWebGLObjects(i);this.autoClear&&this.clear();r.autoUpdateMatrix&&r.updateMatrix();
|
|
x.set(r.matrix.flatten());L.set(r.projectionMatrix.flatten());n=0;for(l=i.__webGLObjects.length;n<l;n++){s=i.__webGLObjects[n];o=s.object;s=s.buffer;if(o.visible){this.setupMatrices(o,r);this.renderPass(r,A,G,o,s,THREE.NormalBlending,false)}}n=0;for(l=i.__webGLObjects.length;n<l;n++){s=i.__webGLObjects[n];o=s.object;s=s.buffer;if(o.visible){this.setupMatrices(o,r);this.renderPass(r,A,G,o,s,THREE.AdditiveBlending,false);this.renderPass(r,A,G,o,s,THREE.SubtractiveBlending,false);this.renderPass(r,A,
|
|
G,o,s,THREE.AdditiveBlending,true);this.renderPass(r,A,G,o,s,THREE.SubtractiveBlending,true);this.renderPass(r,A,G,o,s,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(i){var r,n,l,s,o,A;if(!i.__webGLObjects){i.__webGLObjects=[];i.__webGLObjectsMap={}}r=0;for(n=i.objects.length;r<n;r++){l=i.objects[r];if(i.__webGLObjectsMap[l.id]==undefined)i.__webGLObjectsMap[l.id]={};A=i.__webGLObjectsMap[l.id];if(l instanceof THREE.Mesh)for(o in l.geometry.geometryChunks){s=l.geometry.geometryChunks[o];
|
|
s.__webGLVertexBuffer||this.createBuffers(l,o);if(A[o]==undefined){s={buffer:s,object:l};i.__webGLObjects.push(s);A[o]=1}}}};this.removeObject=function(i,r){var n,l;for(n=i.__webGLObjects.length-1;n>=0;n--){l=i.__webGLObjects[n].object;r==l&&i.__webGLObjects.splice(n,1)}};this.setupMatrices=function(i,r){i.autoUpdateMatrix&&i.updateMatrix();t.multiply(r.matrix,i.matrix);z.set(t.flatten());u=THREE.Matrix4.makeInvert3x3(t).transpose();v.set(u.m);E.set(i.matrix.flatten())};this.loadMatrices=function(i){c.uniformMatrix4fv(i.uniforms.viewMatrix,
|
|
false,x);c.uniformMatrix4fv(i.uniforms.modelViewMatrix,false,z);c.uniformMatrix4fv(i.uniforms.projectionMatrix,false,L);c.uniformMatrix3fv(i.uniforms.normalMatrix,false,v);c.uniformMatrix4fv(i.uniforms.objectMatrix,false,E)};this.loadCamera=function(i,r){c.uniform3f(i.uniforms.cameraPosition,r.position.x,r.position.y,r.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,r){if(i){!r||r=="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};var O={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3}},
|
|
fragment_shader:"uniform float mNear;\nuniform float mFar;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), 1.0 );\n}",vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{},fragment_shader:"varying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, 1.0 );\n}",vertex_shader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"}}};
|
|
THREE.RenderableObject=function(){this.z=this.object=null};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.faceMaterials=this.meshMaterials=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.materials=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.materials=null};
|
|
var GeometryUtils={merge:function(a,b){var e=b instanceof THREE.Mesh,d=a.vertices.length,g=e?b.geometry:b,f=a.vertices,k=g.vertices,h=a.faces,j=g.faces,c=a.uvs;g=g.uvs;e&&b.updateMatrix();for(var w=0,B=k.length;w<B;w++){var t=new THREE.Vertex(k[w].position.clone());e&&b.matrix.multiplyVector3(t.position);f.push(t)}w=0;for(B=j.length;w<B;w++){k=j[w];var u,x=k.vertexNormals;if(k instanceof THREE.Face3)u=new THREE.Face3(k.a+d,k.b+d,k.c+d);else if(k instanceof THREE.Face4)u=new THREE.Face4(k.a+d,k.b+
|
|
d,k.c+d,k.d+d);u.centroid.copy(k.centroid);u.normal.copy(k.normal);e=0;for(f=x.length;e<f;e++){t=x[e];u.vertexNormals.push(t.clone())}u.materials=k.materials.slice();h.push(u)}w=0;for(B=g.length;w<B;w++){d=g[w];h=[];e=0;for(f=d.length;e<f;e++)h.push(new THREE.UV(d[e].u,d[e].v));c.push(h)}}},ImageUtils={loadTexture:function(a,b){var e=new Image;e.onload=function(){this.loaded=true};e.src=a;return new THREE.Texture(e,b)},loadArray:function(a){var b,e,d=[];b=d.loadCount=0;for(e=a.length;b<e;++b){d[b]=
|
|
new Image;d[b].loaded=0;d[b].onload=function(){d.loadCount+=1;this.loaded=true};d[b].src=a[b]}return d}},SceneUtils={addMesh:function(a,b,e,d,g,f,k,h,j,c){b=new THREE.Mesh(b,c);b.scale.x=b.scale.y=b.scale.z=e;b.position.x=d;b.position.y=g;b.position.z=f;b.rotation.x=k;b.rotation.y=h;b.rotation.z=j;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,e){var d=ShaderUtils.lib.cube;d.uniforms.tCube.texture=e;e=new THREE.MeshShaderMaterial({fragment_shader:d.fragment_shader,vertex_shader:d.vertex_shader,
|
|
uniforms:d.uniforms});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),e);a.addObject(b);return b},addPanoramaCube:function(a,b,e){var d=[];d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[0])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[1])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[2])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[3])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[4])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[5])}));
|
|
mesh=new THREE.Mesh(new Cube(b,b,b,1,1,d,true),new THREE.MeshFaceMaterial);a.addObject(mesh);return mesh},addPanoramaCubePlanes:function(a,b,e){var d=b/2;b=new Plane(b,b);var g=Math.PI/2,f=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-d,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[5])}));SceneUtils.addMesh(a,b,1,-d,0,0,0,g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[0])}));SceneUtils.addMesh(a,b,1,d,0,0,0,-g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[1])}));SceneUtils.addMesh(a,
|
|
b,1,0,d,0,g,0,f,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[2])}));SceneUtils.addMesh(a,b,1,0,-d,0,-g,0,f,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[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:{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},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 bool enableDiffuse;\nuniform bool enableAO;\nuniform sampler2D tDiffuse;\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 diffuseTex = vec3( 1.0, 1.0, 1.0 );\nvec3 aoTex = vec3( 1.0, 1.0, 1.0 );\nvec3 normalTex = normalize( texture2D( tNormal, vUv ).xyz * 2.0 - 1.0 );\nif( enableDiffuse )\ndiffuseTex = texture2D( tDiffuse, vUv ).xyz;\nif( enableAO )\naoTex = 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 * diffuseTex, 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}"},
|
|
basic:{uniforms:{},vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"void main() {\ngl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);\n}"},cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertex_shader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",
|
|
fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"}}},Cube=function(a,b,e,d,g,f,k,h){function j(z,L,v,E,m,O,i,r){var n,l=d||1,s=g||1,o=l+1,A=s+1,G=m/2,C=O/2;m=m/l;O=O/s;var H=c.vertices.length;if(z=="x"&&L=="y"||z=="y"&&L=="x")n="z";else if(z=="x"&&L=="z"||z=="z"&&L=="x")n="y";else if(z=="z"&&L=="y"||z=="y"&&L=="z")n="x";for(iy=0;iy<A;iy++)for(ix=0;ix<
|
|
o;ix++){var V=new THREE.Vector3;V[z]=(ix*m-G)*v;V[L]=(iy*O-C)*E;V[n]=i;c.vertices.push(new THREE.Vertex(V))}for(iy=0;iy<s;iy++)for(ix=0;ix<l;ix++){c.faces.push(new THREE.Face4(ix+o*iy+H,ix+o*(iy+1)+H,ix+1+o*(iy+1)+H,ix+1+o*iy+H,null,r));c.uvs.push([new THREE.UV(ix/l,iy/s),new THREE.UV(ix/l,(iy+1)/s),new THREE.UV((ix+1)/l,(iy+1)/s),new THREE.UV((ix+1)/l,iy/s)])}}THREE.Geometry.call(this);var c=this,w=a/2,B=b/2,t=e/2;k=k?-1:1;if(f!==undefined)if(f instanceof Array)this.materials=f;else{this.materials=
|
|
[];for(var u=0;u<6;u++)this.materials.push([f])}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(h!=undefined)for(var x in h)if(this.sides[x]!=undefined)this.sides[x]=h[x];this.sides.px&&j("z","y",1*k,-1,e,b,-w,this.materials[0]);this.sides.nx&&j("z","y",-1*k,-1,e,b,w,this.materials[1]);this.sides.py&&j("x","z",1*k,1,a,e,B,this.materials[2]);this.sides.ny&&j("x","z",1*k,-1,a,e,-B,this.materials[3]);this.sides.pz&&j("x","y",1*k,-1,a,b,t,this.materials[4]);this.sides.nz&&
|
|
j("x","y",-1*k,-1,a,b,-t,this.materials[5]);(function(){for(var z=[],L=[],v=0,E=c.vertices.length;v<E;v++){for(var m=c.vertices[v],O=false,i=0,r=z.length;i<r;i++){var n=z[i];if(m.position.x==n.position.x&&m.position.y==n.position.y&&m.position.z==n.position.z){L[v]=i;O=true;break}}if(!O){L[v]=z.length;z.push(new THREE.Vertex(m.position.clone()))}}v=0;for(E=c.faces.length;v<E;v++){m=c.faces[v];m.a=L[m.a];m.b=L[m.b];m.c=L[m.c];m.d=L[m.d]}c.vertices=z})();this.computeCentroids();this.computeFaceNormals();
|
|
this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
|
|
var Cylinder=function(a,b,e,d,g){function f(c,w,B){k.vertices.push(new THREE.Vertex(new THREE.Vector3(c,w,B)))}THREE.Geometry.call(this);var k=this,h=Math.PI,j;for(j=0;j<a;j++)f(Math.sin(2*h*j/a)*b,Math.cos(2*h*j/a)*b,0);for(j=0;j<a;j++)f(Math.sin(2*h*j/a)*e,Math.cos(2*h*j/a)*e,d);for(j=0;j<a;j++)k.faces.push(new THREE.Face4(j,j+a,a+(j+1)%a,(j+1)%a));if(e!=0){f(0,0,-g);for(j=a;j<a+a/2;j++)k.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){f(0,0,d+g);for(j=a+a/2;j<
|
|
2*a;j++)k.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,e,d){THREE.Geometry.call(this);var g,f=a/2,k=b/2;e=e||1;d=d||1;var h=e+1,j=d+1;a=a/e;var c=b/d;for(g=0;g<j;g++)for(b=0;b<h;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-f,-(g*c-k),0)));for(g=0;g<d;g++)for(b=0;b<e;b++){this.faces.push(new THREE.Face4(b+h*g,b+h*(g+1),b+1+h*(g+1),b+1+h*g));this.uvs.push([new THREE.UV(b/e,g/d),new THREE.UV(b/e,(g+1)/d),new THREE.UV((b+1)/e,(g+1)/d),new THREE.UV((b+1)/e,g/d)])}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};
|
|
Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
|
|
var Sphere=function(a,b,e){THREE.Geometry.call(this);var d,g=Math.PI,f=Math.max(3,b||8),k=Math.max(2,e||6);b=[];for(e=0;e<k+1;e++){d=e/k;var h=a*Math.cos(d*g),j=a*Math.sin(d*g),c=[],w=0;for(d=0;d<f;d++){var B=2*d/f,t=j*Math.sin(B*g);B=j*Math.cos(B*g);(e==0||e==k)&&d>0||(w=this.vertices.push(new THREE.Vertex(new THREE.Vector3(B,h,t)))-1);c.push(w)}b.push(c)}var u,x,z;g=b.length;for(e=0;e<g;e++){f=b[e].length;if(e>0)for(d=0;d<f;d++){c=d==f-1;k=b[e][c?0:d+1];h=b[e][c?f-1:d];j=b[e-1][c?f-1:d];c=b[e-1][c?
|
|
0:d+1];t=e/(g-1);u=(e-1)/(g-1);x=(d+1)/f;B=d/f;w=new THREE.UV(1-x,t);t=new THREE.UV(1-B,t);B=new THREE.UV(1-B,u);var L=new THREE.UV(1-x,u);if(e<b.length-1){u=this.vertices[k].position.clone();x=this.vertices[h].position.clone();z=this.vertices[j].position.clone();u.normalize();x.normalize();z.normalize();this.faces.push(new THREE.Face3(k,h,j,[new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(z.x,z.y,z.z)]));this.uvs.push([w,t,B])}if(e>1){u=this.vertices[k].position.clone();
|
|
x=this.vertices[j].position.clone();z=this.vertices[c].position.clone();u.normalize();x.normalize();z.normalize();this.faces.push(new THREE.Face3(k,j,c,[new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(z.x,z.y,z.z)]));this.uvs.push([w,B,L])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
|
|
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 e=document.createElement("script");e.type="text/javascript";e.onload=b;e.src=a;document.getElementsByTagName("head")[0].appendChild(e)},loadAscii:function(a,b,e){var d=(new Date).getTime();a=new Worker(a);a.onmessage=function(g){THREE.Loader.prototype.createModel(g.data,b,e)};a.postMessage(d)},loadBinary:function(a,b,e){var d=(new Date).getTime();a=new Worker(a);var g=this.showProgress?THREE.Loader.prototype.updateProgress:null;a.onmessage=function(f){THREE.Loader.prototype.loadAjaxBuffers(f.data.buffers,
|
|
f.data.materials,b,e,g)};a.onerror=function(f){alert("worker.onerror: "+f.message+"\n"+f.data);f.preventDefault()};a.postMessage(d)},loadAjaxBuffers:function(a,b,e,d,g){var f=new XMLHttpRequest,k=d+"/"+a,h=0;f.onreadystatechange=function(){if(f.readyState==4)f.status==200||f.status==0?THREE.Loader.prototype.createBinModel(f.responseText,e,d,b):alert("Couldn't load ["+k+"] ["+f.status+"]");else if(f.readyState==3){if(g){if(h==0)h=f.getResponseHeader("Content-Length");g({total:h,loaded:f.responseText.length})}}else if(f.readyState==
|
|
2)h=f.getResponseHeader("Content-Length")};f.open("GET",k,true);f.overrideMimeType("text/plain; charset=x-user-defined");f.setRequestHeader("Content-Type","text/plain");f.send(null)},createBinModel:function(a,b,e,d){var g=function(f){function k(p,q){var y=w(p,q),N=w(p,q+1),R=w(p,q+2),ba=w(p,q+3),fa=(ba<<1&255|R>>7)-127;y=(R&127)<<16|N<<8|y;if(y==0&&fa==-127)return 0;return(1-2*(ba>>7))*(1+y*Math.pow(2,-23))*Math.pow(2,fa)}function h(p,q){var y=w(p,q),N=w(p,q+1),R=w(p,q+2);return(w(p,q+3)<<24)+(R<<
|
|
16)+(N<<8)+y}function j(p,q){var y=w(p,q);return(w(p,q+1)<<8)+y}function c(p,q){var y=w(p,q);return y>127?y-256:y}function w(p,q){return p.charCodeAt(q)&255}function B(p){var q,y,N;q=h(a,p);y=h(a,p+r);N=h(a,p+n);p=j(a,p+l);THREE.Loader.prototype.f3(v,q,y,N,p)}function t(p){var q,y,N,R,ba,fa;q=h(a,p);y=h(a,p+r);N=h(a,p+n);R=j(a,p+l);ba=h(a,p+s);fa=h(a,p+o);p=h(a,p+A);THREE.Loader.prototype.f3n(v,O,q,y,N,R,ba,fa,p)}function u(p){var q,y,N,R;q=h(a,p);y=h(a,p+G);N=h(a,p+C);R=h(a,p+H);p=j(a,p+V);THREE.Loader.prototype.f4(v,
|
|
q,y,N,R,p)}function x(p){var q,y,N,R,ba,fa,na,da;q=h(a,p);y=h(a,p+G);N=h(a,p+C);R=h(a,p+H);ba=j(a,p+V);fa=h(a,p+D);na=h(a,p+Q);da=h(a,p+K);p=h(a,p+P);THREE.Loader.prototype.f4n(v,O,q,y,N,R,ba,fa,na,da,p)}function z(p){var q,y;q=h(a,p);y=h(a,p+W);p=h(a,p+Y);THREE.Loader.prototype.uv3(v,i[q*2],i[q*2+1],i[y*2],i[y*2+1],i[p*2],i[p*2+1])}function L(p){var q,y,N;q=h(a,p);y=h(a,p+I);N=h(a,p+J);p=h(a,p+T);THREE.Loader.prototype.uv4(v,i[q*2],i[q*2+1],i[y*2],i[y*2+1],i[N*2],i[N*2+1],i[p*2],i[p*2+1])}var v=
|
|
this,E=0,m,O=[],i=[],r,n,l,s,o,A,G,C,H,V,D,Q,K,P,W,Y,I,J,T;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(v,d,f);m={signature:a.substr(E,8),header_bytes:w(a,E+8),vertex_coordinate_bytes:w(a,E+9),normal_coordinate_bytes:w(a,E+10),uv_coordinate_bytes:w(a,E+11),vertex_index_bytes:w(a,E+12),normal_index_bytes:w(a,E+13),uv_index_bytes:w(a,E+14),material_index_bytes:w(a,E+15),nvertices:h(a,E+16),nnormals:h(a,E+16+4),nuvs:h(a,E+16+8),ntri_flat:h(a,E+16+12),ntri_smooth:h(a,E+16+16),ntri_flat_uv:h(a,
|
|
E+16+20),ntri_smooth_uv:h(a,E+16+24),nquad_flat:h(a,E+16+28),nquad_smooth:h(a,E+16+32),nquad_flat_uv:h(a,E+16+36),nquad_smooth_uv:h(a,E+16+40)};E+=m.header_bytes;r=m.vertex_index_bytes;n=m.vertex_index_bytes*2;l=m.vertex_index_bytes*3;s=m.vertex_index_bytes*3+m.material_index_bytes;o=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes;A=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*2;G=m.vertex_index_bytes;C=m.vertex_index_bytes*2;H=m.vertex_index_bytes*3;V=m.vertex_index_bytes*
|
|
4;D=m.vertex_index_bytes*4+m.material_index_bytes;Q=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes;K=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*2;P=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*3;W=m.uv_index_bytes;Y=m.uv_index_bytes*2;I=m.uv_index_bytes;J=m.uv_index_bytes*2;T=m.uv_index_bytes*3;E+=function(p){var q,y,N,R=m.vertex_coordinate_bytes*3,ba=p+m.nvertices*R;for(p=p;p<ba;p+=R){q=k(a,p);y=k(a,p+m.vertex_coordinate_bytes);N=
|
|
k(a,p+m.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(v,q,y,N)}return m.nvertices*R}(E);E+=function(p){var q,y,N,R=m.normal_coordinate_bytes*3,ba=p+m.nnormals*R;for(p=p;p<ba;p+=R){q=c(a,p);y=c(a,p+m.normal_coordinate_bytes);N=c(a,p+m.normal_coordinate_bytes*2);O.push(q/127,y/127,N/127)}return m.nnormals*R}(E);E+=function(p){var q,y,N=m.uv_coordinate_bytes*2,R=p+m.nuvs*N;for(p=p;p<R;p+=N){q=k(a,p);y=k(a,p+m.uv_coordinate_bytes);i.push(q,y)}return m.nuvs*N}(E);E+=function(p){var q,y=m.vertex_index_bytes*
|
|
3+m.material_index_bytes,N=p+m.ntri_flat*y;for(q=p;q<N;q+=y)B(q);return N-p}(E);E+=function(p){var q,y=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*3,N=p+m.ntri_smooth*y;for(q=p;q<N;q+=y)t(q);return N-p}(E);E+=function(p){var q,y=m.vertex_index_bytes*3+m.material_index_bytes,N=y+m.uv_index_bytes*3,R=p+m.ntri_flat_uv*N;for(q=p;q<R;q+=N){B(q);z(q+y)}return R-p}(E);E+=function(p){var q,y=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*3,N=y+m.uv_index_bytes*3,
|
|
R=p+m.ntri_smooth_uv*N;for(q=p;q<R;q+=N){t(q);z(q+y)}return R-p}(E);E+=function(p){var q,y=m.vertex_index_bytes*4+m.material_index_bytes,N=p+m.nquad_flat*y;for(q=p;q<N;q+=y)u(q);return N-p}(E);E+=function(p){var q,y=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*4,N=p+m.nquad_smooth*y;for(q=p;q<N;q+=y)x(q);return N-p}(E);E+=function(p){var q,y=m.vertex_index_bytes*4+m.material_index_bytes,N=y+m.uv_index_bytes*4,R=p+m.nquad_flat_uv*N;for(q=p;q<R;q+=N){u(q);L(q+y)}return R-p}(E);
|
|
E+=function(p){var q,y=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*4,N=y+m.uv_index_bytes*4,R=p+m.nquad_smooth_uv*N;for(q=p;q<R;q+=N){x(q);L(q+y)}return R-p}(E);this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;b(new g(e))},createModel:function(a,b,e){var d=function(g){var f=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(f,a.materials,g);(function(){var k,h,j,c,w;k=0;for(h=
|
|
a.vertices.length;k<h;k+=3){j=a.vertices[k];c=a.vertices[k+1];w=a.vertices[k+2];THREE.Loader.prototype.v(f,j,c,w)}})();(function(){function k(x,z){THREE.Loader.prototype.f3(f,x[z],x[z+1],x[z+2],x[z+3])}function h(x,z){THREE.Loader.prototype.f3n(f,a.normals,x[z],x[z+1],x[z+2],x[z+3],x[z+4],x[z+5],x[z+6])}function j(x,z){THREE.Loader.prototype.f4(f,x[z],x[z+1],x[z+2],x[z+3],x[z+4])}function c(x,z){THREE.Loader.prototype.f4n(f,a.normals,x[z],x[z+1],x[z+2],x[z+3],x[z+4],x[z+5],x[z+6],x[z+7],x[z+8])}function w(x,
|
|
z){var L,v,E;L=x[z];v=x[z+1];E=x[z+2];THREE.Loader.prototype.uv3(f,a.uvs[L*2],a.uvs[L*2+1],a.uvs[v*2],a.uvs[v*2+1],a.uvs[E*2],a.uvs[E*2+1])}function B(x,z){var L,v,E,m;L=x[z];v=x[z+1];E=x[z+2];m=x[z+3];THREE.Loader.prototype.uv4(f,a.uvs[L*2],a.uvs[L*2+1],a.uvs[v*2],a.uvs[v*2+1],a.uvs[E*2],a.uvs[E*2+1],a.uvs[m*2],a.uvs[m*2+1])}var t,u;t=0;for(u=a.triangles.length;t<u;t+=4)k(a.triangles,t);t=0;for(u=a.triangles_uv.length;t<u;t+=7){k(a.triangles_uv,t);w(a.triangles_uv,t+4)}t=0;for(u=a.triangles_n.length;t<
|
|
u;t+=7)h(a.triangles_n,t);t=0;for(u=a.triangles_n_uv.length;t<u;t+=10){h(a.triangles_n_uv,t);w(a.triangles_n_uv,t+7)}t=0;for(u=a.quads.length;t<u;t+=5)j(a.quads,t);t=0;for(u=a.quads_uv.length;t<u;t+=9){j(a.quads_uv,t);B(a.quads_uv,t+5)}t=0;for(u=a.quads_n.length;t<u;t+=9)c(a.quads_n,t);t=0;for(u=a.quads_n_uv.length;t<u;t+=13){c(a.quads_n_uv,t);B(a.quads_n_uv,t+9)}})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};d.prototype=new THREE.Geometry;d.prototype.constructor=
|
|
d;b(new d(e))},v:function(a,b,e,d){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,e,d)))},f3:function(a,b,e,d,g){a.faces.push(new THREE.Face3(b,e,d,null,a.materials[g]))},f4:function(a,b,e,d,g,f){a.faces.push(new THREE.Face4(b,e,d,g,null,a.materials[f]))},f3n:function(a,b,e,d,g,f,k,h,j){f=a.materials[f];var c=b[h*3],w=b[h*3+1];h=b[h*3+2];var B=b[j*3],t=b[j*3+1];j=b[j*3+2];a.faces.push(new THREE.Face3(e,d,g,[new THREE.Vector3(b[k*3],b[k*3+1],b[k*3+2]),new THREE.Vector3(c,w,h),new THREE.Vector3(B,
|
|
t,j)],f))},f4n:function(a,b,e,d,g,f,k,h,j,c,w){k=a.materials[k];var B=b[j*3],t=b[j*3+1];j=b[j*3+2];var u=b[c*3],x=b[c*3+1];c=b[c*3+2];var z=b[w*3],L=b[w*3+1];w=b[w*3+2];a.faces.push(new THREE.Face4(e,d,g,f,[new THREE.Vector3(b[h*3],b[h*3+1],b[h*3+2]),new THREE.Vector3(B,t,j),new THREE.Vector3(u,x,c),new THREE.Vector3(z,L,w)],k))},uv3:function(a,b,e,d,g,f,k){var h=[];h.push(new THREE.UV(b,e));h.push(new THREE.UV(d,g));h.push(new THREE.UV(f,k));a.uvs.push(h)},uv4:function(a,b,e,d,g,f,k,h,j){var c=[];
|
|
c.push(new THREE.UV(b,e));c.push(new THREE.UV(d,g));c.push(new THREE.UV(f,k));c.push(new THREE.UV(h,j));a.uvs.push(c)},init_materials:function(a,b,e){a.materials=[];for(var d=0;d<b.length;++d)a.materials[d]=[THREE.Loader.prototype.createMaterial(b[d],e)]},createMaterial:function(a,b){function e(f){f=Math.log(f)/Math.LN2;return Math.floor(f)==f}var d,g;if(a.map_diffuse&&b){g=document.createElement("canvas");d=new THREE.MeshLambertMaterial({map:new THREE.Texture(g)});g=new Image;g.onload=function(){if(!e(this.width)||
|
|
!e(this.height)){var f=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),k=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));d.map.image.width=f;d.map.image.height=k;d.map.image.getContext("2d").drawImage(this,0,0,f,k)}else d.map.image=this;d.map.image.loaded=1};g.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){g=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;d=new THREE.MeshLambertMaterial({color:g,opacity:a.transparency})}else d=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):
|
|
new THREE.MeshLambertMaterial({color:15658734});return d}};
|