mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-22 19:36:13 +10:00
Added normal + ambient occlusion + displacement mapping demo.
A lot of things going on in this commit:
- added tangents computation for geometries
- mesh must have UV coordinates
- to be called explicitly once geometry is loaded like this: geometry.computeTangents()
- tangents are stored in Vertex objects
- quads are not solved properly (though workaround hack seems to work at least somehow, as far as each vertex appears at least somewhere)
- extended VBOs in WebGLRenderer to include tangent streams (when available)
- added "normal" shader to ShaderUtils (to be used with MeshShaderMaterial)
- Blinn-Phong with one directional and one point light (7 varyings gone, just one spare)
- normal maps are in tangent space
- displacement maps use simple luminance value (could be changed if better precision is needed)
- displacement mapping uses vertex texture fetch
- this requires GPU with Shader Model 3.0
- not currently supported in ANGLE
- for this, added "supportsVertexTextures" method to WebGLRenderer API, so that application can handle this
This commit is contained in:
+120
-115
@@ -5,59 +5,62 @@ THREE.Color.prototype={setRGB:function(a,b,d){this.r=a;this.g=b;this.b=d;if(this
|
||||
THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},unit:function(){this.multiplyScalar(1/this.length());return this},length:function(){return Math.sqrt(this.x*
|
||||
this.x+this.y*this.y)},lengthSq:function(){return this.x*this.x+this.y*this.y},negate:function(){this.x=-this.x;this.y=-this.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},toString:function(){return"THREE.Vector2 ("+this.x+", "+this.y+")"}};THREE.Vector3=function(a,b,d){this.x=a||0;this.y=b||0;this.z=d||0};
|
||||
THREE.Vector3.prototype={set:function(a,b,d){this.x=a;this.y=b;this.z=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
|
||||
cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,g=this.z;this.x=d*a.z-g*a.y;this.y=g*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
|
||||
cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,f=this.z;this.x=d*a.z-f*a.y;this.y=f*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
|
||||
a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+d*d+a*a)},distanceToSquared:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return b*b+d*d+a*a},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},negate:function(){this.x=-this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=
|
||||
Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<1.0E-4&&Math.abs(this.y)<1.0E-4&&Math.abs(this.z)<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},toString:function(){return"THREE.Vector3 ( "+this.x+", "+this.y+", "+this.z+" )"}};
|
||||
THREE.Vector4=function(a,b,d,g){this.x=a||0;this.y=b||0;this.z=d||0;this.w=g||1};
|
||||
THREE.Vector4.prototype={set:function(a,b,d,g){this.x=a;this.y=b;this.z=d;this.w=g;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;
|
||||
THREE.Vector4=function(a,b,d,f){this.x=a||0;this.y=b||0;this.z=d||0;this.w=f||1};
|
||||
THREE.Vector4.prototype={set:function(a,b,d,f){this.x=a;this.y=b;this.z=d;this.w=f;return this},copy:function(a){this.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,d,g=a.objects,j=[];a=0;for(b=g.length;a<b;a++){d=g[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(n,m){return n.distance-m.distance});return j},intersectObject:function(a){function b(L,N,O,v){v=v.clone().subSelf(N);O=O.clone().subSelf(N);var f=L.clone().subSelf(N);L=v.dot(v);N=v.dot(O);v=v.dot(f);var k=O.dot(O);O=O.dot(f);f=1/(L*k-N*N);k=(k*v-N*O)*f;L=(L*O-N*v)*f;return k>0&&L>0&&k+L<1}var d,g,j,n,m,l,o,c,F,D,
|
||||
w,x=a.geometry,I=x.vertices,G=[];d=0;for(g=x.faces.length;d<g;d++){j=x.faces[d];D=this.origin.clone();w=this.direction.clone();n=a.matrix.multiplyVector3(I[j.a].position.clone());m=a.matrix.multiplyVector3(I[j.b].position.clone());l=a.matrix.multiplyVector3(I[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(I[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());F=w.dot(c);if(F<0){c=c.dot((new THREE.Vector3).sub(n,D))/F;D=D.addSelf(w.multiplyScalar(c));
|
||||
if(j instanceof THREE.Face3){if(b(D,n,m,l)){j={distance:this.origin.distanceTo(D),point:D,face:j,object:a};G.push(j)}}else if(j instanceof THREE.Face4)if(b(D,n,m,o)||b(D,m,l,o)){j={distance:this.origin.distanceTo(D),point:D,face:j,object:a};G.push(j)}}}return G}};
|
||||
THREE.Rectangle=function(){function a(){n=g-b;m=j-d}var b,d,g,j,n,m,l=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return n};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return g};this.getBottom=function(){return j};this.set=function(o,c,F,D){l=false;b=o;d=c;g=F;j=D;a()};this.addPoint=function(o,c){if(l){l=false;b=o;d=c;g=o;j=c}else{b=Math.min(b,o);d=Math.min(d,c);g=Math.max(g,
|
||||
o);j=Math.max(j,c)}a()};this.addRectangle=function(o){if(l){l=false;b=o.getLeft();d=o.getTop();g=o.getRight();j=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());g=Math.max(g,o.getRight());j=Math.max(j,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;g+=o;j+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());g=Math.min(g,o.getRight());j=Math.min(j,o.getBottom());a()};this.instersects=function(o){return Math.min(g,o.getRight())-Math.max(b,o.getLeft())>=
|
||||
0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){l=true;j=g=d=b=0;a()};this.isEmpty=function(){return l};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+g+", top: "+d+", bottom: "+j+", width: "+n+", height: "+m+" )"}};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.Ray.prototype={intersectScene:function(a){var b,d,f=a.objects,j=[];a=0;for(b=f.length;a<b;a++){d=f[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(m,n){return m.distance-n.distance});return j},intersectObject:function(a){function b(J,L,M,u){u=u.clone().subSelf(L);M=M.clone().subSelf(L);var e=J.clone().subSelf(L);J=u.dot(u);L=u.dot(M);u=u.dot(e);var k=M.dot(M);M=M.dot(e);e=1/(J*k-L*L);k=(k*u-L*M)*e;J=(J*M-L*u)*e;return k>0&&J>0&&k+J<1}var d,f,j,m,n,l,o,c,E,C,
|
||||
x,z=a.geometry,H=z.vertices,G=[];d=0;for(f=z.faces.length;d<f;d++){j=z.faces[d];C=this.origin.clone();x=this.direction.clone();m=a.matrix.multiplyVector3(H[j.a].position.clone());n=a.matrix.multiplyVector3(H[j.b].position.clone());l=a.matrix.multiplyVector3(H[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(H[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());E=x.dot(c);if(E<0){c=c.dot((new THREE.Vector3).sub(m,C))/E;C=C.addSelf(x.multiplyScalar(c));
|
||||
if(j instanceof THREE.Face3){if(b(C,m,n,l)){j={distance:this.origin.distanceTo(C),point:C,face:j,object:a};G.push(j)}}else if(j instanceof THREE.Face4)if(b(C,m,n,o)||b(C,n,l,o)){j={distance:this.origin.distanceTo(C),point:C,face:j,object:a};G.push(j)}}}return G}};
|
||||
THREE.Rectangle=function(){function a(){m=f-b;n=j-d}var b,d,f,j,m,n,l=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return m};this.getHeight=function(){return n};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return f};this.getBottom=function(){return j};this.set=function(o,c,E,C){l=false;b=o;d=c;f=E;j=C;a()};this.addPoint=function(o,c){if(l){l=false;b=o;d=c;f=o;j=c}else{b=Math.min(b,o);d=Math.min(d,c);f=Math.max(f,
|
||||
o);j=Math.max(j,c)}a()};this.addRectangle=function(o){if(l){l=false;b=o.getLeft();d=o.getTop();f=o.getRight();j=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());f=Math.max(f,o.getRight());j=Math.max(j,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;f+=o;j+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());f=Math.min(f,o.getRight());j=Math.min(j,o.getBottom());a()};this.instersects=function(o){return Math.min(f,o.getRight())-Math.max(b,o.getLeft())>=
|
||||
0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){l=true;j=f=d=b=0;a()};this.isEmpty=function(){return l};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+f+", top: "+d+", bottom: "+j+", width: "+m+", height: "+n+" )"}};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(){};
|
||||
THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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},lookAt:function(a,b,d){var g=new THREE.Vector3,j=new THREE.Vector3,n=new THREE.Vector3;n.sub(a,b).normalize();g.cross(d,n).normalize();j.cross(n,g).normalize();this.n11=g.x;this.n12=g.y;this.n13=g.z;this.n14=-g.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=n.x;this.n32=n.y;this.n33=n.z;this.n34=-n.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,g=a.z,j=1/(this.n41*b+this.n42*
|
||||
d+this.n43*g+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*g+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*g+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*g+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,g=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*g+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*g+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*g+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*g+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
|
||||
a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,g=a.n12,j=a.n13,n=a.n14,m=a.n21,l=a.n22,o=a.n23,c=a.n24,F=a.n31,D=a.n32,w=a.n33,x=a.n34,I=a.n41,G=a.n42,L=a.n43,N=a.n44,O=b.n11,v=b.n12,f=b.n13,k=b.n14,e=b.n21,p=b.n22,h=b.n23,i=b.n24,s=b.n31,r=b.n32,M=b.n33,A=b.n34,H=b.n41,Q=b.n42,u=b.n43,
|
||||
R=b.n44;this.n11=d*O+g*e+j*s+n*H;this.n12=d*v+g*p+j*r+n*Q;this.n13=d*f+g*h+j*M+n*u;this.n14=d*k+g*i+j*A+n*R;this.n21=m*O+l*e+o*s+c*H;this.n22=m*v+l*p+o*r+c*Q;this.n23=m*f+l*h+o*M+c*u;this.n24=m*k+l*i+o*A+c*R;this.n31=F*O+D*e+w*s+x*H;this.n32=F*v+D*p+w*r+x*Q;this.n33=F*f+D*h+w*M+x*u;this.n34=F*k+D*i+w*A+x*R;this.n41=I*O+G*e+L*s+N*H;this.n42=I*v+G*p+L*r+N*Q;this.n43=I*f+G*h+L*M+N*u;this.n44=I*k+G*i+L*A+N*R},multiplySelf:function(a){var b=this.n11,d=this.n12,g=this.n13,j=this.n14,n=this.n21,m=this.n22,
|
||||
l=this.n23,o=this.n24,c=this.n31,F=this.n32,D=this.n33,w=this.n34,x=this.n41,I=this.n42,G=this.n43,L=this.n44;this.n11=b*a.n11+d*a.n21+g*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+g*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+g*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+g*a.n34+j*a.n44;this.n21=n*a.n11+m*a.n21+l*a.n31+o*a.n41;this.n22=n*a.n12+m*a.n22+l*a.n32+o*a.n42;this.n23=n*a.n13+m*a.n23+l*a.n33+o*a.n43;this.n24=n*a.n14+m*a.n24+l*a.n34+o*a.n44;this.n31=c*a.n11+F*a.n21+D*a.n31+w*a.n41;this.n32=c*a.n12+F*a.n22+
|
||||
D*a.n32+w*a.n42;this.n33=c*a.n13+F*a.n23+D*a.n33+w*a.n43;this.n34=c*a.n14+F*a.n24+D*a.n34+w*a.n44;this.n41=x*a.n11+I*a.n21+G*a.n31+L*a.n41;this.n42=x*a.n12+I*a.n22+G*a.n32+L*a.n42;this.n43=x*a.n13+I*a.n23+G*a.n33+L*a.n43;this.n44=x*a.n14+I*a.n24+G*a.n34+L*a.n44},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},determinant:function(){return this.n14*
|
||||
a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44},lookAt:function(a,b,d){var f=new THREE.Vector3,j=new THREE.Vector3,m=new THREE.Vector3;m.sub(a,b).normalize();f.cross(d,m).normalize();j.cross(m,f).normalize();this.n11=f.x;this.n12=f.y;this.n13=f.z;this.n14=-f.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=m.x;this.n32=m.y;this.n33=m.z;this.n34=-m.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,f=a.z,j=1/(this.n41*b+this.n42*
|
||||
d+this.n43*f+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*f+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*f+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*f+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,f=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*f+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*f+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*f+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*f+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
|
||||
a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,f=a.n12,j=a.n13,m=a.n14,n=a.n21,l=a.n22,o=a.n23,c=a.n24,E=a.n31,C=a.n32,x=a.n33,z=a.n34,H=a.n41,G=a.n42,J=a.n43,L=a.n44,M=b.n11,u=b.n12,e=b.n13,k=b.n14,g=b.n21,q=b.n22,h=b.n23,i=b.n24,r=b.n31,p=b.n32,D=b.n33,w=b.n34,I=b.n41,S=b.n42,t=b.n43,
|
||||
O=b.n44;this.n11=d*M+f*g+j*r+m*I;this.n12=d*u+f*q+j*p+m*S;this.n13=d*e+f*h+j*D+m*t;this.n14=d*k+f*i+j*w+m*O;this.n21=n*M+l*g+o*r+c*I;this.n22=n*u+l*q+o*p+c*S;this.n23=n*e+l*h+o*D+c*t;this.n24=n*k+l*i+o*w+c*O;this.n31=E*M+C*g+x*r+z*I;this.n32=E*u+C*q+x*p+z*S;this.n33=E*e+C*h+x*D+z*t;this.n34=E*k+C*i+x*w+z*O;this.n41=H*M+G*g+J*r+L*I;this.n42=H*u+G*q+J*p+L*S;this.n43=H*e+G*h+J*D+L*t;this.n44=H*k+G*i+J*w+L*O},multiplySelf:function(a){var b=this.n11,d=this.n12,f=this.n13,j=this.n14,m=this.n21,n=this.n22,
|
||||
l=this.n23,o=this.n24,c=this.n31,E=this.n32,C=this.n33,x=this.n34,z=this.n41,H=this.n42,G=this.n43,J=this.n44;this.n11=b*a.n11+d*a.n21+f*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+f*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+f*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+f*a.n34+j*a.n44;this.n21=m*a.n11+n*a.n21+l*a.n31+o*a.n41;this.n22=m*a.n12+n*a.n22+l*a.n32+o*a.n42;this.n23=m*a.n13+n*a.n23+l*a.n33+o*a.n43;this.n24=m*a.n14+n*a.n24+l*a.n34+o*a.n44;this.n31=c*a.n11+E*a.n21+C*a.n31+x*a.n41;this.n32=c*a.n12+E*a.n22+
|
||||
C*a.n32+x*a.n42;this.n33=c*a.n13+E*a.n23+C*a.n33+x*a.n43;this.n34=c*a.n14+E*a.n24+C*a.n34+x*a.n44;this.n41=z*a.n11+H*a.n21+G*a.n31+J*a.n41;this.n42=z*a.n12+H*a.n22+G*a.n32+J*a.n42;this.n43=z*a.n13+H*a.n23+G*a.n33+J*a.n43;this.n44=z*a.n14+H*a.n24+G*a.n34+J*a.n44},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},determinant:function(){return this.n14*
|
||||
this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
|
||||
this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,g){var j=b[d];b[d]=b[g];b[g]=j}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
|
||||
this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,f){var j=b[d];b[d]=b[f];b[f]=j}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
|
||||
"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){return[this.n11,this.n21,this.n31,this.n41,this.n12,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
|
||||
toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var g=new THREE.Matrix4;g.n14=a;g.n24=b;g.n34=d;return g};THREE.Matrix4.scaleMatrix=function(a,b,d){var g=new THREE.Matrix4;g.n11=a;g.n22=b;g.n33=d;return g};
|
||||
toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var f=new THREE.Matrix4;f.n14=a;f.n24=b;f.n34=d;return f};THREE.Matrix4.scaleMatrix=function(a,b,d){var f=new THREE.Matrix4;f.n11=a;f.n22=b;f.n33=d;return f};
|
||||
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 d=new THREE.Matrix4,g=Math.cos(b),j=Math.sin(b),n=1-g,m=a.x,l=a.y,o=a.z;d.n11=n*m*m+g;d.n12=n*m*l-j*o;d.n13=n*m*o+j*l;d.n21=n*m*l+j*o;d.n22=n*l*l+g;d.n23=n*l*o-j*m;d.n31=n*m*o-j*l;d.n32=n*l*o+j*m;d.n33=n*o*o+g;return d};
|
||||
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,f=Math.cos(b),j=Math.sin(b),m=1-f,n=a.x,l=a.y,o=a.z;d.n11=m*n*n+f;d.n12=m*n*l-j*o;d.n13=m*n*o+j*l;d.n21=m*n*l+j*o;d.n22=m*l*l+f;d.n23=m*l*o-j*n;d.n31=m*n*o-j*l;d.n32=m*l*o+j*n;d.n33=m*o*o+f;return d};
|
||||
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 d=b[10]*b[5]-b[6]*b[9],g=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],n=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],l=-b[6]*b[0]+b[2]*b[4],o=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],F=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*n+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*g;a.m[2]=b*j;a.m[3]=b*n;a.m[4]=b*m;a.m[5]=b*l;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*F;return a};
|
||||
THREE.Matrix4.makeFrustum=function(a,b,d,g,j,n){var m,l,o;m=new THREE.Matrix4;l=2*j/(b-a);o=2*j/(g-d);a=(b+a)/(b-a);d=(g+d)/(g-d);g=-(n+j)/(n-j);j=-2*n*j/(n-j);m.n11=l;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=o;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=g;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,g){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,g)};
|
||||
THREE.Matrix4.makeOrtho=function(a,b,d,g,j,n){var m,l,o,c;m=new THREE.Matrix4;l=b-a;o=d-g;c=n-j;a=(b+a)/l;d=(d+g)/o;j=(n+j)/c;m.n11=2/l;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/o;m.n23=0;m.n24=-d;m.n31=0;m.n32=0;m.n33=-2/c;m.n34=-j;m.n41=0;m.n42=0;m.n43=0;m.n44=1;return m};
|
||||
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.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
|
||||
THREE.Face3=function(a,b,d,g,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
|
||||
THREE.Face4=function(a,b,d,g,j,n){this.a=a;this.b=b;this.c=d;this.d=g;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=n instanceof Array?n:[n]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
|
||||
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
|
||||
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],f=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],m=-b[10]*b[4]+b[6]*b[8],n=b[10]*b[0]-b[2]*b[8],l=-b[6]*b[0]+b[2]*b[4],o=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],E=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*m+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*f;a.m[2]=b*j;a.m[3]=b*m;a.m[4]=b*n;a.m[5]=b*l;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*E;return a};
|
||||
THREE.Matrix4.makeFrustum=function(a,b,d,f,j,m){var n,l,o;n=new THREE.Matrix4;l=2*j/(b-a);o=2*j/(f-d);a=(b+a)/(b-a);d=(f+d)/(f-d);f=-(m+j)/(m-j);j=-2*m*j/(m-j);n.n11=l;n.n12=0;n.n13=a;n.n14=0;n.n21=0;n.n22=o;n.n23=d;n.n24=0;n.n31=0;n.n32=0;n.n33=f;n.n34=j;n.n41=0;n.n42=0;n.n43=-1;n.n44=0;return n};THREE.Matrix4.makePerspective=function(a,b,d,f){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,f)};
|
||||
THREE.Matrix4.makeOrtho=function(a,b,d,f,j,m){var n,l,o,c;n=new THREE.Matrix4;l=b-a;o=d-f;c=m-j;a=(b+a)/l;d=(d+f)/o;j=(m+j)/c;n.n11=2/l;n.n12=0;n.n13=0;n.n14=-a;n.n21=0;n.n22=2/o;n.n23=0;n.n24=-d;n.n31=0;n.n32=0;n.n33=-2/c;n.n34=-j;n.n41=0;n.n42=0;n.n43=0;n.n44=1;return n};
|
||||
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
|
||||
THREE.Face3=function(a,b,d,f,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
|
||||
THREE.Face4=function(a,b,d,f,j,m){this.a=a;this.b=b;this.c=d;this.d=f;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=m instanceof Array?m:[m]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
|
||||
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={};this.hasTangents=false};
|
||||
THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
|
||||
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,g,j,n,m,l=new THREE.Vector3,o=new THREE.Vector3;g=0;for(j=this.vertices.length;g<j;g++){n=this.vertices[g];n.normal.set(0,0,0)}g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];if(a&&n.vertexNormals.length){l.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)l.addSelf(n.vertexNormals[b]);l.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];m=this.vertices[n.c];l.sub(m.position,
|
||||
d.position);o.sub(b.position,d.position);l.crossSelf(o)}l.isZero()||l.normalize();n.normal.copy(l)}},computeVertexNormals:function(){var a,b=[],d,g;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal)}else if(g instanceof THREE.Face4){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal);b[g.d].addSelf(g.normal)}}a=
|
||||
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone()}else if(g instanceof THREE.Face4){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone();g.vertexNormals[3]=b[g.d].clone()}}},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;
|
||||
if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(F){var D=[];b=0;for(d=F.length;b<d;b++)F[b]==undefined?D.push("undefined"):D.push(F[b].toString());return D.join("_")}var b,d,g,j,n,m,l,o,c={};g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];m=n.material;l=a(m);if(c[l]==undefined)c[l]={hash:l,counter:0};o=c[l].hash+"_"+c[l].counter;if(this.geometryChunks[o]==
|
||||
undefined)this.geometryChunks[o]={faces:[],material:m,vertices:0};n=n instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+n>65535){c[l].counter+=1;o=c[l].hash+"_"+c[l].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:m,vertices:0}}this.geometryChunks[o].faces.push(g);this.geometryChunks[o].vertices+=n}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
|
||||
THREE.Camera=function(a,b,d,g){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,g);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
|
||||
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,f,j,m,n,l=new THREE.Vector3,o=new THREE.Vector3;f=0;for(j=this.vertices.length;f<j;f++){m=this.vertices[f];m.normal.set(0,0,0)}f=0;for(j=this.faces.length;f<j;f++){m=this.faces[f];if(a&&m.vertexNormals.length){l.set(0,0,0);b=0;for(d=m.normal.length;b<d;b++)l.addSelf(m.vertexNormals[b]);l.divideScalar(3)}else{b=this.vertices[m.a];d=this.vertices[m.b];n=this.vertices[m.c];l.sub(n.position,
|
||||
d.position);o.sub(b.position,d.position);l.crossSelf(o)}l.isZero()||l.normalize();m.normal.copy(l)}},computeVertexNormals:function(){var a,b=[],d,f;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){f=this.faces[a];if(f instanceof THREE.Face3){b[f.a].addSelf(f.normal);b[f.b].addSelf(f.normal);b[f.c].addSelf(f.normal)}else if(f instanceof THREE.Face4){b[f.a].addSelf(f.normal);b[f.b].addSelf(f.normal);b[f.c].addSelf(f.normal);b[f.d].addSelf(f.normal)}}a=
|
||||
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){f=this.faces[a];if(f instanceof THREE.Face3){f.vertexNormals[0]=b[f.a].clone();f.vertexNormals[1]=b[f.b].clone();f.vertexNormals[2]=b[f.c].clone()}else if(f instanceof THREE.Face4){f.vertexNormals[0]=b[f.a].clone();f.vertexNormals[1]=b[f.b].clone();f.vertexNormals[2]=b[f.c].clone();f.vertexNormals[3]=b[f.d].clone()}}},computeTangents:function(){function a(w,I,S,t){m=w.vertices[I].position;n=w.vertices[S].position;
|
||||
l=w.vertices[t].position;o=j[0];c=j[1];E=j[2];C=n.x-m.x;x=l.x-m.x;z=n.y-m.y;H=l.y-m.y;G=n.z-m.z;J=l.z-m.z;L=c.u-o.u;M=E.u-o.u;u=c.v-o.v;e=E.v-o.v;k=1/(L*e-M*u);i.set((e*C-u*x)*k,(e*z-u*H)*k,(e*G-u*J)*k);r.set((L*x-M*C)*k,(L*H-M*z)*k,(L*J-M*G)*k);q[I].addSelf(i);q[S].addSelf(i);q[t].addSelf(i);h[I].addSelf(r);h[S].addSelf(r);h[t].addSelf(r)}var b,d,f,j,m,n,l,o,c,E,C,x,z,H,G,J,L,M,u,e,k,g,q=[],h=[],i=new THREE.Vector3,r=new THREE.Vector3,p=new THREE.Vector3,D=new THREE.Vector3;g=new THREE.Vector3;b=
|
||||
0;for(d=this.vertices.length;b<d;b++){q[b]=new THREE.Vector3;h[b]=new THREE.Vector3}b=0;for(d=this.faces.length;b<d;b++){f=this.faces[b];j=this.uvs[b];if(f instanceof THREE.Face3){a(this,f.a,f.b,f.c);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2])}else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.c);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);
|
||||
this.vertices[f.c].normal.copy(f.vertexNormals[2]);this.vertices[f.d].normal.copy(f.vertexNormals[3])}}b=0;for(d=this.vertices.length;b<d;b++){g.copy(this.vertices[b].normal);f=q[b];p.copy(f);p.subSelf(g.multiplyScalar(g.dot(f))).normalize();D.cross(this.vertices[b].normal,f);test=D.dot(h[b]);f=test<0?-1:1;this.vertices[b].tangent.set(p.x,p.y,p.z,f)}this.hasTangents=true},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=
|
||||
vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(E){var C=[];b=0;for(d=E.length;b<d;b++)E[b]==undefined?C.push("undefined"):C.push(E[b].toString());return C.join("_")}var b,d,f,j,m,n,l,o,c={};f=0;for(j=this.faces.length;f<j;f++){m=this.faces[f];n=m.material;l=a(n);if(c[l]==undefined)c[l]={hash:l,counter:0};o=c[l].hash+"_"+c[l].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:n,
|
||||
vertices:0};m=m instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+m>65535){c[l].counter+=1;o=c[l].hash+"_"+c[l].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:n,vertices:0}}this.geometryChunks[o].faces.push(f);this.geometryChunks[o].vertices+=m}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
|
||||
THREE.Camera=function(a,b,d,f){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,f);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
|
||||
THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
|
||||
THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
|
||||
THREE.Object3D=function(){this.id=THREE.Object3DCounter.value++;this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.matrix=new THREE.Matrix4;this.translationMatrix=new THREE.Matrix4;this.rotationMatrix=new THREE.Matrix4;this.scaleMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.autoUpdateMatrix=this.visible=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);
|
||||
this.rotationMatrix=THREE.Matrix4.rotationXMatrix(this.rotation.x);this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.scaleMatrix=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);this.matrix.multiplySelf(this.rotationMatrix);this.matrix.multiplySelf(this.scaleMatrix)}};THREE.Object3DCounter={value:0};
|
||||
THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.Line=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
|
||||
THREE.Mesh=function(a,b,d){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;d&&this.normalizeUVs();this.geometry.computeBoundingBox()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;
|
||||
THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,g,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(g=j.length;d<g;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
|
||||
THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,f,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(f=j.length;d<f;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
|
||||
THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;this.linewidth=1;this.linejoin=this.linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.linewidth!==undefined)this.linewidth=a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+
|
||||
this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
|
||||
THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(15658734);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=
|
||||
@@ -82,91 +85,93 @@ undefined)this.uniforms=a.uniforms;if(a.shading!==undefined)this.shading=a.shadi
|
||||
THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.offset=new THREE.Vector2;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+
|
||||
this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
|
||||
THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
|
||||
THREE.Texture=function(a,b,d,g,j,n){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=g!==undefined?g:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=n!==undefined?n:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
|
||||
THREE.Texture=function(a,b,d,f,j,m){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=f!==undefined?f:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=m!==undefined?m:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
|
||||
this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
|
||||
THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
|
||||
THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
|
||||
THREE.Projector=function(){function a(O,v){var f=0,k=1,e=O.z+O.w,p=v.z+v.w,h=-O.z+O.w,i=-v.z+v.w;if(e>=0&&p>=0&&h>=0&&i>=0)return true;else if(e<0&&p<0||h<0&&i<0)return false;else{if(e<0)f=Math.max(f,e/(e-p));else if(p<0)k=Math.min(k,e/(e-p));if(h<0)f=Math.max(f,h/(h-i));else if(i<0)k=Math.min(k,h/(h-i));if(k<f)return false;else{O.lerpSelf(v,f);v.lerpSelf(O,1-k);return true}}}var b=null,d,g,j,n=[],m,l,o=[],c,F,D=[],w=new THREE.Vector4,x=new THREE.Matrix4,I=new THREE.Matrix4,G=new THREE.Vector4,L=
|
||||
new THREE.Vector4,N;this.projectScene=function(O,v){var f,k,e,p,h,i,s,r,M,A,H,Q,u,R,y,z,E;b=[];j=l=F=0;v.autoUpdateMatrix&&v.updateMatrix();x.multiply(v.projectionMatrix,v.matrix);s=O.objects;f=0;for(k=s.length;f<k;f++){r=s[f];r.autoUpdateMatrix&&r.updateMatrix();M=r.matrix;A=r.rotationMatrix;H=r.material;Q=r.overdraw;if(r instanceof THREE.Mesh){u=r.geometry.vertices;e=0;for(p=u.length;e<p;e++){R=u[e];R.positionWorld.copy(R.position);M.multiplyVector3(R.positionWorld);y=R.positionScreen;y.copy(R.positionWorld);
|
||||
x.multiplyVector4(y);y.multiplyScalar(1/y.w);R.__visible=y.z>0&&y.z<1}R=r.geometry.faces;e=0;for(p=R.length;e<p;e++){y=R[e];if(y instanceof THREE.Face3){h=u[y.a];i=u[y.b];z=u[y.c];if(h.__visible&&i.__visible&&z.__visible)if(r.doubleSided||r.flipSided!=(z.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(z.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<0){d=n[j]=n[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);
|
||||
d.v3.positionWorld.copy(z.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(z.positionScreen);d.normalWorld.copy(y.normal);A.multiplyVector3(d.normalWorld);d.centroidWorld.copy(y.centroid);M.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);x.multiplyVector3(d.centroidScreen);z=y.vertexNormals;N=d.vertexNormalsWorld;h=0;for(i=z.length;h<i;h++){E=N[h]=N[h]||new THREE.Vector3;E.copy(z[h]);A.multiplyVector3(E)}d.z=
|
||||
d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=y.material;d.overdraw=Q;if(r.geometry.uvs[e]){d.uvs[0]=r.geometry.uvs[e][0];d.uvs[1]=r.geometry.uvs[e][1];d.uvs[2]=r.geometry.uvs[e][2]}b.push(d);j++}}else if(y instanceof THREE.Face4){h=u[y.a];i=u[y.b];z=u[y.c];E=u[y.d];if(h.__visible&&i.__visible&&z.__visible&&E.__visible)if(r.doubleSided||r.flipSided!=((E.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(E.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<
|
||||
0||(i.positionScreen.x-z.positionScreen.x)*(E.positionScreen.y-z.positionScreen.y)-(i.positionScreen.y-z.positionScreen.y)*(E.positionScreen.x-z.positionScreen.x)<0)){d=n[j]=n[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);d.v3.positionWorld.copy(E.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(E.positionScreen);d.normalWorld.copy(y.normal);A.multiplyVector3(d.normalWorld);
|
||||
d.centroidWorld.copy(y.centroid);M.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);x.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=y.material;d.overdraw=Q;if(r.geometry.uvs[e]){d.uvs[0]=r.geometry.uvs[e][0];d.uvs[1]=r.geometry.uvs[e][1];d.uvs[2]=r.geometry.uvs[e][3]}b.push(d);j++;g=n[j]=n[j]||new THREE.RenderableFace3;g.v1.positionWorld.copy(i.positionWorld);g.v2.positionWorld.copy(z.positionWorld);g.v3.positionWorld.copy(E.positionWorld);
|
||||
g.v1.positionScreen.copy(i.positionScreen);g.v2.positionScreen.copy(z.positionScreen);g.v3.positionScreen.copy(E.positionScreen);g.normalWorld.copy(d.normalWorld);g.centroidWorld.copy(d.centroidWorld);g.centroidScreen.copy(d.centroidScreen);g.z=g.centroidScreen.z;g.meshMaterial=H;g.faceMaterial=y.material;g.overdraw=Q;if(r.geometry.uvs[e]){g.uvs[0]=r.geometry.uvs[e][1];g.uvs[1]=r.geometry.uvs[e][2];g.uvs[2]=r.geometry.uvs[e][3]}b.push(g);j++}}}}else if(r instanceof THREE.Line){I.multiply(x,M);u=r.geometry.vertices;
|
||||
R=u[0];R.positionScreen.copy(R.position);I.multiplyVector4(R.positionScreen);e=1;for(p=u.length;e<p;e++){h=u[e];h.positionScreen.copy(h.position);I.multiplyVector4(h.positionScreen);i=u[e-1];G.copy(h.positionScreen);L.copy(i.positionScreen);if(a(G,L)){G.multiplyScalar(1/G.w);L.multiplyScalar(1/L.w);m=o[l]=o[l]||new THREE.RenderableLine;m.v1.positionScreen.copy(G);m.v2.positionScreen.copy(L);m.z=Math.max(G.z,L.z);m.material=r.material;b.push(m);l++}}}else if(r instanceof THREE.Particle){w.set(r.position.x,
|
||||
r.position.y,r.position.z,1);x.multiplyVector4(w);w.z/=w.w;if(w.z>0&&w.z<1){c=D[F]=D[F]||new THREE.RenderableParticle;c.x=w.x/w.w;c.y=w.y/w.w;c.z=w.z;c.rotation=r.rotation.z;c.scale.x=r.scale.x*Math.abs(c.x-(w.x+v.projectionMatrix.n11)/(w.w+v.projectionMatrix.n14));c.scale.y=r.scale.y*Math.abs(c.y-(w.y+v.projectionMatrix.n22)/(w.w+v.projectionMatrix.n24));c.material=r.material;b.push(c);F++}}}b.sort(function(W,J){return J.z-W.z});return b};this.unprojectVector=function(O,v){var f=new THREE.Matrix4;
|
||||
f.multiply(THREE.Matrix4.makeInvert(v.matrix),THREE.Matrix4.makeInvert(v.projectionMatrix));f.multiplyVector3(O);return O}};
|
||||
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,g,j,n;this.domElement=document.createElement("div");this.setSize=function(m,l){d=m;g=l;j=d/2;n=g/2};this.render=function(m,l){var o,c,F,D,w,x,I,G;a=b.projectScene(m,l);o=0;for(c=a.length;o<c;o++){w=a[o];if(w instanceof THREE.RenderableParticle){I=w.x*j+j;G=w.y*n+n;F=0;for(D=w.material.length;F<D;F++){x=w.material[F];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=I+"px";x.style.top=G+"px"}}}}}};
|
||||
THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),g,j,n,m,l=d.getContext("2d"),o=1,c=0,F=null,D=null,w=1,x=Math.min,I=Math.max,G,L,N,O,v,f,k,e,p,h=new THREE.Color,i=new THREE.Color,s=new THREE.Color,r=new THREE.Color,M=new THREE.Color,A,H,Q,u,R,y,z,E,W,J,B=new THREE.Rectangle,U=new THREE.Rectangle,X=new THREE.Rectangle,S=false,P=new THREE.Color,Z=new THREE.Color,ia=new THREE.Color,ja=new THREE.Color,La=Math.PI*2,Y=new THREE.Vector3,na,oa,Ca,ba,pa,
|
||||
va,la=16;na=document.createElement("canvas");na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Ca=oa.getImageData(0,0,2,2);ba=Ca.data;pa=document.createElement("canvas");pa.width=pa.height=la;va=pa.getContext("2d");va.translate(-la/2,-la/2);va.scale(la,la);la--;this.domElement=d;this.autoClear=true;this.setSize=function(fa,wa){g=fa;j=wa;n=g/2;m=j/2;d.width=g;d.height=j;B.set(-n,-m,n,m)};this.clear=function(){if(!U.isEmpty()){U.inflate(1);U.minSelf(B);l.clearRect(U.getX(),
|
||||
U.getY(),U.getWidth(),U.getHeight());U.empty()}};this.render=function(fa,wa){function Ma(q){var T,K,t,C=q.lights;Z.setRGB(0,0,0);ia.setRGB(0,0,0);ja.setRGB(0,0,0);q=0;for(T=C.length;q<T;q++){K=C[q];t=K.color;if(K instanceof THREE.AmbientLight){Z.r+=t.r;Z.g+=t.g;Z.b+=t.b}else if(K instanceof THREE.DirectionalLight){ia.r+=t.r;ia.g+=t.g;ia.b+=t.b}else if(K instanceof THREE.PointLight){ja.r+=t.r;ja.g+=t.g;ja.b+=t.b}}}function xa(q,T,K,t){var C,V,aa,ca,da=q.lights;q=0;for(C=da.length;q<C;q++){V=da[q];
|
||||
aa=V.color;ca=V.intensity;if(V instanceof THREE.DirectionalLight){V=K.dot(V.position)*ca;if(V>0){t.r+=aa.r*V;t.g+=aa.g*V;t.b+=aa.b*V}}else if(V instanceof THREE.PointLight){Y.sub(V.position,T);Y.normalize();V=K.dot(Y)*ca;if(V>0){t.r+=aa.r*V;t.g+=aa.g*V;t.b+=aa.b*V}}}}function Na(q,T,K){if(K.opacity!=0){Da(K.opacity);ya(K.blending);var t,C,V,aa,ca,da;if(K instanceof THREE.ParticleBasicMaterial){if(K.map){aa=K.map;ca=aa.width>>1;da=aa.height>>1;C=T.scale.x*n;V=T.scale.y*m;K=C*ca;t=V*da;X.set(q.x-K,
|
||||
q.y-t,q.x+K,q.y+t);if(B.instersects(X)){l.save();l.translate(q.x,q.y);l.rotate(-T.rotation);l.scale(C,-V);l.translate(-ca,-da);l.drawImage(aa,0,0);l.restore()}}}else if(K instanceof THREE.ParticleCircleMaterial){if(S){P.r=Z.r+ia.r+ja.r;P.g=Z.g+ia.g+ja.g;P.b=Z.b+ia.b+ja.b;h.r=K.color.r*P.r;h.g=K.color.g*P.g;h.b=K.color.b*P.b;h.updateStyleString()}else h.__styleString=K.color.__styleString;K=T.scale.x*n;t=T.scale.y*m;X.set(q.x-K,q.y-t,q.x+K,q.y+t);if(B.instersects(X)){C=h.__styleString;if(D!=C)l.fillStyle=
|
||||
D=C;l.save();l.translate(q.x,q.y);l.rotate(-T.rotation);l.scale(K,t);l.beginPath();l.arc(0,0,1,0,La,true);l.closePath();l.fill();l.restore()}}}}function Oa(q,T,K,t){if(t.opacity!=0){Da(t.opacity);ya(t.blending);l.beginPath();l.moveTo(q.positionScreen.x,q.positionScreen.y);l.lineTo(T.positionScreen.x,T.positionScreen.y);l.closePath();if(t instanceof THREE.LineBasicMaterial){h.__styleString=t.color.__styleString;q=t.linewidth;if(w!=q)l.lineWidth=w=q;q=h.__styleString;if(F!=q)l.strokeStyle=F=q;l.stroke();
|
||||
X.inflate(t.linewidth*2)}}}function Ha(q,T,K,t,C,V){if(C.opacity!=0){Da(C.opacity);ya(C.blending);O=q.positionScreen.x;v=q.positionScreen.y;f=T.positionScreen.x;k=T.positionScreen.y;e=K.positionScreen.x;p=K.positionScreen.y;l.beginPath();l.moveTo(O,v);l.lineTo(f,k);l.lineTo(e,p);l.lineTo(O,v);l.closePath();if(C instanceof THREE.MeshBasicMaterial)if(C.map)C.map.image.loaded&&C.map.mapping instanceof THREE.UVMapping&&qa(O,v,f,k,e,p,C.map.image,t.uvs[0].u,t.uvs[0].v,t.uvs[1].u,t.uvs[1].v,t.uvs[2].u,
|
||||
t.uvs[2].v);else if(C.env_map){if(C.env_map.image.loaded)if(C.env_map.mapping instanceof THREE.SphericalReflectionMapping){q=wa.matrix;Y.copy(t.vertexNormalsWorld[0]);R=(Y.x*q.n11+Y.y*q.n12+Y.z*q.n13)*0.5+0.5;y=-(Y.x*q.n21+Y.y*q.n22+Y.z*q.n23)*0.5+0.5;Y.copy(t.vertexNormalsWorld[1]);z=(Y.x*q.n11+Y.y*q.n12+Y.z*q.n13)*0.5+0.5;E=-(Y.x*q.n21+Y.y*q.n22+Y.z*q.n23)*0.5+0.5;Y.copy(t.vertexNormalsWorld[2]);W=(Y.x*q.n11+Y.y*q.n12+Y.z*q.n13)*0.5+0.5;J=-(Y.x*q.n21+Y.y*q.n22+Y.z*q.n23)*0.5+0.5;qa(O,v,f,k,e,p,
|
||||
C.env_map.image,R,y,z,E,W,J)}}else C.wireframe?za(C.color.__styleString,C.wireframe_linewidth):Aa(C.color.__styleString);else if(C instanceof THREE.MeshLambertMaterial){if(C.map&&!C.wireframe){C.map.mapping instanceof THREE.UVMapping&&qa(O,v,f,k,e,p,C.map.image,t.uvs[0].u,t.uvs[0].v,t.uvs[1].u,t.uvs[1].v,t.uvs[2].u,t.uvs[2].v);ya(THREE.SubtractiveBlending)}if(S)if(!C.wireframe&&C.shading==THREE.SmoothShading&&t.vertexNormalsWorld.length==3){i.r=s.r=r.r=Z.r;i.g=s.g=r.g=Z.g;i.b=s.b=r.b=Z.b;xa(V,t.v1.positionWorld,
|
||||
t.vertexNormalsWorld[0],i);xa(V,t.v2.positionWorld,t.vertexNormalsWorld[1],s);xa(V,t.v3.positionWorld,t.vertexNormalsWorld[2],r);M.r=(s.r+r.r)*0.5;M.g=(s.g+r.g)*0.5;M.b=(s.b+r.b)*0.5;u=Ia(i,s,r,M);qa(O,v,f,k,e,p,u,0,0,1,0,0,1)}else{P.r=Z.r;P.g=Z.g;P.b=Z.b;xa(V,t.centroidWorld,t.normalWorld,P);h.r=C.color.r*P.r;h.g=C.color.g*P.g;h.b=C.color.b*P.b;h.updateStyleString();C.wireframe?za(h.__styleString,C.wireframe_linewidth):Aa(h.__styleString)}else C.wireframe?za(C.color.__styleString,C.wireframe_linewidth):
|
||||
Aa(C.color.__styleString)}else if(C instanceof THREE.MeshDepthMaterial){A=C.__2near;H=C.__farPlusNear;Q=C.__farMinusNear;i.r=i.g=i.b=1-A/(H-q.positionScreen.z*Q);s.r=s.g=s.b=1-A/(H-T.positionScreen.z*Q);r.r=r.g=r.b=1-A/(H-K.positionScreen.z*Q);M.r=(s.r+r.r)*0.5;M.g=(s.g+r.g)*0.5;M.b=(s.b+r.b)*0.5;u=Ia(i,s,r,M);qa(O,v,f,k,e,p,u,0,0,1,0,0,1)}else if(C instanceof THREE.MeshNormalMaterial){h.r=Ea(t.normalWorld.x);h.g=Ea(t.normalWorld.y);h.b=Ea(t.normalWorld.z);h.updateStyleString();C.wireframe?za(h.__styleString,
|
||||
C.wireframe_linewidth):Aa(h.__styleString)}}}function za(q,T){if(F!=q)l.strokeStyle=F=q;if(w!=T)l.lineWidth=w=T;l.stroke();X.inflate(T*2)}function Aa(q){if(D!=q)l.fillStyle=D=q;l.fill()}function qa(q,T,K,t,C,V,aa,ca,da,ra,ha,sa,ta){var ka,ga;ka=aa.width-1;ga=aa.height-1;ca*=ka;da*=ga;ra*=ka;ha*=ga;sa*=ka;ta*=ga;K-=q;t-=T;C-=q;V-=T;ra-=ca;ha-=da;sa-=ca;ta-=da;ga=1/(ra*ta-sa*ha);ka=(ta*K-ha*C)*ga;ha=(ta*t-ha*V)*ga;K=(ra*C-sa*K)*ga;t=(ra*V-sa*t)*ga;q=q-ka*ca-K*da;T=T-ha*ca-t*da;l.save();l.transform(ka,
|
||||
ha,K,t,q,T);l.clip();l.drawImage(aa,0,0);l.restore()}function Da(q){if(o!=q)l.globalAlpha=o=q}function ya(q){if(c!=q){switch(q){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}c=q}}function Ia(q,T,K,t){ba[0]=I(0,x(255,~~(q.r*255)));ba[1]=I(0,x(255,~~(q.g*255)));ba[2]=I(0,x(255,~~(q.b*255)));ba[4]=I(0,x(255,~~(T.r*255)));ba[5]=I(0,x(255,
|
||||
~~(T.g*255)));ba[6]=I(0,x(255,~~(T.b*255)));ba[8]=I(0,x(255,~~(K.r*255)));ba[9]=I(0,x(255,~~(K.g*255)));ba[10]=I(0,x(255,~~(K.b*255)));ba[12]=I(0,x(255,~~(t.r*255)));ba[13]=I(0,x(255,~~(t.g*255)));ba[14]=I(0,x(255,~~(t.b*255)));oa.putImageData(Ca,0,0);va.drawImage(na,0,0);return pa}function Ea(q){return q<0?x((1+q)*0.5,0.5):0.5+x(q*0.5,0.5)}function Fa(q,T){var K=T.x-q.x,t=T.y-q.y,C=1/Math.sqrt(K*K+t*t);K*=C;t*=C;T.x+=K;T.y+=t;q.x-=K;q.y-=t}var Ba,Ja,$,ea,ma,Ga,Ka,ua;l.setTransform(1,0,0,-1,n,m);
|
||||
this.autoClear&&this.clear();a=b.projectScene(fa,wa);(S=fa.lights.length>0)&&Ma(fa);Ba=0;for(Ja=a.length;Ba<Ja;Ba++){$=a[Ba];X.empty();if($ instanceof THREE.RenderableParticle){G=$;G.x*=n;G.y*=m;ea=0;for(ma=$.material.length;ea<ma;ea++)Na(G,$,$.material[ea],fa)}else if($ instanceof THREE.RenderableLine){G=$.v1;L=$.v2;G.positionScreen.x*=n;G.positionScreen.y*=m;L.positionScreen.x*=n;L.positionScreen.y*=m;X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);
|
||||
if(B.instersects(X)){ea=0;for(ma=$.material.length;ea<ma;)Oa(G,L,$,$.material[ea++],fa)}}else if($ instanceof THREE.RenderableFace3){G=$.v1;L=$.v2;N=$.v3;G.positionScreen.x*=n;G.positionScreen.y*=m;L.positionScreen.x*=n;L.positionScreen.y*=m;N.positionScreen.x*=n;N.positionScreen.y*=m;if($.overdraw){Fa(G.positionScreen,L.positionScreen);Fa(L.positionScreen,N.positionScreen);Fa(N.positionScreen,G.positionScreen)}X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);
|
||||
X.addPoint(N.positionScreen.x,N.positionScreen.y);if(B.instersects(X)){ea=0;for(ma=$.meshMaterial.length;ea<ma;){ua=$.meshMaterial[ea++];if(ua instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterial.length;Ga<Ka;)(ua=$.faceMaterial[Ga++])&&Ha(G,L,N,$,ua,fa)}else Ha(G,L,N,$,ua,fa)}}}U.addRectangle(X)}l.setTransform(1,0,0,1,0,0)}};
|
||||
THREE.SVGRenderer=function(){function a(y,z,E){var W,J,B,U;W=0;for(J=y.lights.length;W<J;W++){B=y.lights[W];if(B instanceof THREE.DirectionalLight){U=z.normalWorld.dot(B.position)*B.intensity;if(U>0){E.r+=B.color.r*U;E.g+=B.color.g*U;E.b+=B.color.b*U}}else if(B instanceof THREE.PointLight){i.sub(B.position,z.centroidWorld);i.normalize();U=z.normalWorld.dot(i)*B.intensity;if(U>0){E.r+=B.color.r*U;E.g+=B.color.g*U;E.b+=B.color.b*U}}}}function b(y,z,E,W,J,B){A=g(H++);A.setAttribute("d","M "+y.positionScreen.x+
|
||||
" "+y.positionScreen.y+" L "+z.positionScreen.x+" "+z.positionScreen.y+" L "+E.positionScreen.x+","+E.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)v.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(O){f.r=k.r;f.g=k.g;f.b=k.b;a(B,W,f);v.r=J.color.r*f.r;v.g=J.color.g*f.g;v.b=J.color.b*f.b;v.updateStyleString()}else v.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){h=1-J.__2near/(J.__farPlusNear-W.z*J.__farMinusNear);
|
||||
v.setRGB(h,h,h)}else J instanceof THREE.MeshNormalMaterial&&v.setRGB(j(W.normalWorld.x),j(W.normalWorld.y),j(W.normalWorld.z));J.wireframe?A.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):A.setAttribute("style","fill: "+v.__styleString+"; fill-opacity: "+J.opacity);l.appendChild(A)}function d(y,z,E,W,J,B,U){A=g(H++);A.setAttribute("d",
|
||||
"M "+y.positionScreen.x+" "+y.positionScreen.y+" L "+z.positionScreen.x+" "+z.positionScreen.y+" L "+E.positionScreen.x+","+E.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+"z");if(B instanceof THREE.MeshBasicMaterial)v.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshLambertMaterial)if(O){f.r=k.r;f.g=k.g;f.b=k.b;a(U,J,f);v.r=B.color.r*f.r;v.g=B.color.g*f.g;v.b=B.color.b*f.b;v.updateStyleString()}else v.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshDepthMaterial){h=
|
||||
1-B.__2near/(B.__farPlusNear-J.z*B.__farMinusNear);v.setRGB(h,h,h)}else B instanceof THREE.MeshNormalMaterial&&v.setRGB(j(J.normalWorld.x),j(J.normalWorld.y),j(J.normalWorld.z));B.wireframe?A.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+B.wireframe_linewidth+"; stroke-opacity: "+B.opacity+"; stroke-linecap: "+B.wireframe_linecap+"; stroke-linejoin: "+B.wireframe_linejoin):A.setAttribute("style","fill: "+v.__styleString+"; fill-opacity: "+B.opacity);l.appendChild(A)}
|
||||
function g(y){if(s[y]==null){s[y]=document.createElementNS("http://www.w3.org/2000/svg","path");R==0&&s[y].setAttribute("shape-rendering","crispEdges");return s[y]}return s[y]}function j(y){return y<0?Math.min((1+y)*0.5,0.5):0.5+Math.min(y*0.5,0.5)}var n=null,m=new THREE.Projector,l=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,F,D,w,x,I,G,L=new THREE.Rectangle,N=new THREE.Rectangle,O=false,v=new THREE.Color(16777215),f=new THREE.Color(16777215),k=new THREE.Color(0),e=new THREE.Color(0),
|
||||
p=new THREE.Color(0),h,i=new THREE.Vector3,s=[],r=[],M=[],A,H,Q,u,R=1;this.domElement=l;this.autoClear=true;this.setQuality=function(y){switch(y){case "high":R=1;break;case "low":R=0}};this.setSize=function(y,z){o=y;c=z;F=o/2;D=c/2;l.setAttribute("viewBox",-F+" "+-D+" "+o+" "+c);l.setAttribute("width",o);l.setAttribute("height",c);L.set(-F,-D,F,D)};this.clear=function(){for(;l.childNodes.length>0;)l.removeChild(l.childNodes[0])};this.render=function(y,z){var E,W,J,B,U,X,S,P;this.autoClear&&this.clear();
|
||||
n=m.projectScene(y,z);u=Q=H=0;if(O=y.lights.length>0){S=y.lights;k.setRGB(0,0,0);e.setRGB(0,0,0);p.setRGB(0,0,0);E=0;for(W=S.length;E<W;E++){J=S[E];B=J.color;if(J instanceof THREE.AmbientLight){k.r+=B.r;k.g+=B.g;k.b+=B.b}else if(J instanceof THREE.DirectionalLight){e.r+=B.r;e.g+=B.g;e.b+=B.b}else if(J instanceof THREE.PointLight){p.r+=B.r;p.g+=B.g;p.b+=B.b}}}E=0;for(W=n.length;E<W;E++){S=n[E];N.empty();if(S instanceof THREE.RenderableParticle){w=S;w.x*=F;w.y*=-D;J=0;for(B=S.material.length;J<B;J++)if(P=
|
||||
S.material[J]){U=w;X=S;P=P;var Z=Q++;if(r[Z]==null){r[Z]=document.createElementNS("http://www.w3.org/2000/svg","circle");R==0&&r[Z].setAttribute("shape-rendering","crispEdges")}A=r[Z];A.setAttribute("cx",U.x);A.setAttribute("cy",U.y);A.setAttribute("r",X.scale.x*F);if(P instanceof THREE.ParticleCircleMaterial){if(O){f.r=k.r+e.r+p.r;f.g=k.g+e.g+p.g;f.b=k.b+e.b+p.b;v.r=P.color.r*f.r;v.g=P.color.g*f.g;v.b=P.color.b*f.b;v.updateStyleString()}else v=P.color;A.setAttribute("style","fill: "+v.__styleString)}l.appendChild(A)}}else if(S instanceof
|
||||
THREE.RenderableLine){w=S.v1;x=S.v2;w.positionScreen.x*=F;w.positionScreen.y*=-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);if(L.instersects(N)){J=0;for(B=S.material.length;J<B;)if(P=S.material[J++]){U=w;X=x;P=P;Z=u++;if(M[Z]==null){M[Z]=document.createElementNS("http://www.w3.org/2000/svg","line");R==0&&M[Z].setAttribute("shape-rendering","crispEdges")}A=M[Z];A.setAttribute("x1",U.positionScreen.x);
|
||||
A.setAttribute("y1",U.positionScreen.y);A.setAttribute("x2",X.positionScreen.x);A.setAttribute("y2",X.positionScreen.y);if(P instanceof THREE.LineBasicMaterial){v.__styleString=P.color.__styleString;A.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+P.linewidth+"; stroke-opacity: "+P.opacity+"; stroke-linecap: "+P.linecap+"; stroke-linejoin: "+P.linejoin);l.appendChild(A)}}}}else if(S instanceof THREE.RenderableFace3){w=S.v1;x=S.v2;I=S.v3;w.positionScreen.x*=F;w.positionScreen.y*=
|
||||
-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;I.positionScreen.x*=F;I.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);N.addPoint(I.positionScreen.x,I.positionScreen.y);if(L.instersects(N)){J=0;for(B=S.meshMaterial.length;J<B;){P=S.meshMaterial[J++];if(P instanceof THREE.MeshFaceMaterial){U=0;for(X=S.faceMaterial.length;U<X;)(P=S.faceMaterial[U++])&&b(w,x,I,S,P,y)}else P&&b(w,x,I,S,P,y)}}}else if(S instanceof THREE.RenderableFace4){w=
|
||||
S.v1;x=S.v2;I=S.v3;G=S.v4;w.positionScreen.x*=F;w.positionScreen.y*=-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;I.positionScreen.x*=F;I.positionScreen.y*=-D;G.positionScreen.x*=F;G.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);N.addPoint(I.positionScreen.x,I.positionScreen.y);N.addPoint(G.positionScreen.x,G.positionScreen.y);if(L.instersects(N)){J=0;for(B=S.meshMaterial.length;J<B;){P=S.meshMaterial[J++];if(P instanceof
|
||||
THREE.MeshFaceMaterial){U=0;for(X=S.faceMaterial.length;U<X;)(P=S.faceMaterial[U++])&&d(w,x,I,G,S,P,y)}else P&&d(w,x,I,G,S,P,y)}}}}}};
|
||||
THREE.WebGLRenderer=function(a){function b(f,k){var e=c.createProgram();c.attachShader(e,m("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+f));c.attachShader(e,m("vertex","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"+k));c.linkProgram(e);c.getProgramParameter(e,
|
||||
c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(e,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");e.uniforms={};e.attributes={};return e}function d(f,k){if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,f.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 e=0;e<6;++e)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image[e]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}function g(f,
|
||||
k){if(!f.__webGLTexture&&f.image.loaded){f.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,f.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,l(f.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,l(f.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,l(f.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,l(f.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+
|
||||
k);c.bindTexture(c.TEXTURE_2D,f.__webGLTexture)}function j(f,k){var e,p,h;e=0;for(p=k.length;e<p;e++){h=k[e];f.uniforms[h]=c.getUniformLocation(f,h)}}function n(f,k){var e,p,h;e=0;for(p=k.length;e<p;e++){h=k[e];f.attributes[h]=c.getAttribLocation(f,h);f.attributes[h]>=0&&c.enableVertexAttribArray(f.attributes[h])}}function m(f,k){var e;if(f=="fragment")e=c.createShader(c.FRAGMENT_SHADER);else if(f=="vertex")e=c.createShader(c.VERTEX_SHADER);c.shaderSource(e,k);c.compileShader(e);if(!c.getShaderParameter(e,
|
||||
c.COMPILE_STATUS)){alert(c.getShaderInfoLog(e));return null}return e}function l(f){switch(f){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 o=document.createElement("canvas"),c,F,D,w=new THREE.Matrix4,x,I=new Float32Array(16),G=new Float32Array(16),L=new Float32Array(16),N=new Float32Array(9),O=new Float32Array(16);a=function(f,k){if(f){var e,p,h,i=pointLights=maxDirLights=maxPointLights=0;e=0;for(p=f.lights.length;e<p;e++){h=f.lights[e];h instanceof THREE.DirectionalLight&&i++;h instanceof THREE.PointLight&&pointLights++}if(pointLights+i<=k){maxDirLights=
|
||||
i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(k*i/(pointLights+i));maxPointLights=k-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:k-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(v){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);
|
||||
c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);F=D=function(f,k){var e=[f?"#define MAX_DIR_LIGHTS "+f:"",k?"#define MAX_POINT_LIGHTS "+k:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",f?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",k?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":
|
||||
"",k?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",k?"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;",
|
||||
f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",f?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",f?"}":"",k?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",k?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",k?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
||||
THREE.Projector=function(){function a(M,u){var e=0,k=1,g=M.z+M.w,q=u.z+u.w,h=-M.z+M.w,i=-u.z+u.w;if(g>=0&&q>=0&&h>=0&&i>=0)return true;else if(g<0&&q<0||h<0&&i<0)return false;else{if(g<0)e=Math.max(e,g/(g-q));else if(q<0)k=Math.min(k,g/(g-q));if(h<0)e=Math.max(e,h/(h-i));else if(i<0)k=Math.min(k,h/(h-i));if(k<e)return false;else{M.lerpSelf(u,e);u.lerpSelf(M,1-k);return true}}}var b=null,d,f,j,m=[],n,l,o=[],c,E,C=[],x=new THREE.Vector4,z=new THREE.Matrix4,H=new THREE.Matrix4,G=new THREE.Vector4,J=
|
||||
new THREE.Vector4,L;this.projectScene=function(M,u){var e,k,g,q,h,i,r,p,D,w,I,S,t,O,B,P,Q;b=[];j=l=E=0;u.autoUpdateMatrix&&u.updateMatrix();z.multiply(u.projectionMatrix,u.matrix);r=M.objects;e=0;for(k=r.length;e<k;e++){p=r[e];p.autoUpdateMatrix&&p.updateMatrix();D=p.matrix;w=p.rotationMatrix;I=p.material;S=p.overdraw;if(p instanceof THREE.Mesh){t=p.geometry.vertices;g=0;for(q=t.length;g<q;g++){O=t[g];O.positionWorld.copy(O.position);D.multiplyVector3(O.positionWorld);B=O.positionScreen;B.copy(O.positionWorld);
|
||||
z.multiplyVector4(B);B.multiplyScalar(1/B.w);O.__visible=B.z>0&&B.z<1}O=p.geometry.faces;g=0;for(q=O.length;g<q;g++){B=O[g];if(B instanceof THREE.Face3){h=t[B.a];i=t[B.b];P=t[B.c];if(h.__visible&&i.__visible&&P.__visible)if(p.doubleSided||p.flipSided!=(P.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(P.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<0){d=m[j]=m[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);
|
||||
d.v3.positionWorld.copy(P.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(P.positionScreen);d.normalWorld.copy(B.normal);w.multiplyVector3(d.normalWorld);d.centroidWorld.copy(B.centroid);D.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);z.multiplyVector3(d.centroidScreen);P=B.vertexNormals;L=d.vertexNormalsWorld;h=0;for(i=P.length;h<i;h++){Q=L[h]=L[h]||new THREE.Vector3;Q.copy(P[h]);w.multiplyVector3(Q)}d.z=
|
||||
d.centroidScreen.z;d.meshMaterial=I;d.faceMaterial=B.material;d.overdraw=S;if(p.geometry.uvs[g]){d.uvs[0]=p.geometry.uvs[g][0];d.uvs[1]=p.geometry.uvs[g][1];d.uvs[2]=p.geometry.uvs[g][2]}b.push(d);j++}}else if(B instanceof THREE.Face4){h=t[B.a];i=t[B.b];P=t[B.c];Q=t[B.d];if(h.__visible&&i.__visible&&P.__visible&&Q.__visible)if(p.doubleSided||p.flipSided!=((Q.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(Q.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<
|
||||
0||(i.positionScreen.x-P.positionScreen.x)*(Q.positionScreen.y-P.positionScreen.y)-(i.positionScreen.y-P.positionScreen.y)*(Q.positionScreen.x-P.positionScreen.x)<0)){d=m[j]=m[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);d.v3.positionWorld.copy(Q.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(Q.positionScreen);d.normalWorld.copy(B.normal);w.multiplyVector3(d.normalWorld);
|
||||
d.centroidWorld.copy(B.centroid);D.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);z.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=I;d.faceMaterial=B.material;d.overdraw=S;if(p.geometry.uvs[g]){d.uvs[0]=p.geometry.uvs[g][0];d.uvs[1]=p.geometry.uvs[g][1];d.uvs[2]=p.geometry.uvs[g][3]}b.push(d);j++;f=m[j]=m[j]||new THREE.RenderableFace3;f.v1.positionWorld.copy(i.positionWorld);f.v2.positionWorld.copy(P.positionWorld);f.v3.positionWorld.copy(Q.positionWorld);
|
||||
f.v1.positionScreen.copy(i.positionScreen);f.v2.positionScreen.copy(P.positionScreen);f.v3.positionScreen.copy(Q.positionScreen);f.normalWorld.copy(d.normalWorld);f.centroidWorld.copy(d.centroidWorld);f.centroidScreen.copy(d.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterial=I;f.faceMaterial=B.material;f.overdraw=S;if(p.geometry.uvs[g]){f.uvs[0]=p.geometry.uvs[g][1];f.uvs[1]=p.geometry.uvs[g][2];f.uvs[2]=p.geometry.uvs[g][3]}b.push(f);j++}}}}else if(p instanceof THREE.Line){H.multiply(z,D);t=p.geometry.vertices;
|
||||
O=t[0];O.positionScreen.copy(O.position);H.multiplyVector4(O.positionScreen);g=1;for(q=t.length;g<q;g++){h=t[g];h.positionScreen.copy(h.position);H.multiplyVector4(h.positionScreen);i=t[g-1];G.copy(h.positionScreen);J.copy(i.positionScreen);if(a(G,J)){G.multiplyScalar(1/G.w);J.multiplyScalar(1/J.w);n=o[l]=o[l]||new THREE.RenderableLine;n.v1.positionScreen.copy(G);n.v2.positionScreen.copy(J);n.z=Math.max(G.z,J.z);n.material=p.material;b.push(n);l++}}}else if(p instanceof THREE.Particle){x.set(p.position.x,
|
||||
p.position.y,p.position.z,1);z.multiplyVector4(x);x.z/=x.w;if(x.z>0&&x.z<1){c=C[E]=C[E]||new THREE.RenderableParticle;c.x=x.x/x.w;c.y=x.y/x.w;c.z=x.z;c.rotation=p.rotation.z;c.scale.x=p.scale.x*Math.abs(c.x-(x.x+u.projectionMatrix.n11)/(x.w+u.projectionMatrix.n14));c.scale.y=p.scale.y*Math.abs(c.y-(x.y+u.projectionMatrix.n22)/(x.w+u.projectionMatrix.n24));c.material=p.material;b.push(c);E++}}}b.sort(function(K,y){return y.z-K.z});return b};this.unprojectVector=function(M,u){var e=new THREE.Matrix4;
|
||||
e.multiply(THREE.Matrix4.makeInvert(u.matrix),THREE.Matrix4.makeInvert(u.projectionMatrix));e.multiplyVector3(M);return M}};
|
||||
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,f,j,m;this.domElement=document.createElement("div");this.setSize=function(n,l){d=n;f=l;j=d/2;m=f/2};this.render=function(n,l){var o,c,E,C,x,z,H,G;a=b.projectScene(n,l);o=0;for(c=a.length;o<c;o++){x=a[o];if(x instanceof THREE.RenderableParticle){H=x.x*j+j;G=x.y*m+m;E=0;for(C=x.material.length;E<C;E++){z=x.material[E];if(z instanceof THREE.ParticleDOMMaterial){z=z.domElement;z.style.left=H+"px";z.style.top=G+"px"}}}}}};
|
||||
THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),f,j,m,n,l=d.getContext("2d"),o=1,c=0,E=null,C=null,x=1,z=Math.min,H=Math.max,G,J,L,M,u,e,k,g,q,h=new THREE.Color,i=new THREE.Color,r=new THREE.Color,p=new THREE.Color,D=new THREE.Color,w,I,S,t,O,B,P,Q,K,y,A=new THREE.Rectangle,V=new THREE.Rectangle,X=new THREE.Rectangle,T=false,R=new THREE.Color,Z=new THREE.Color,ia=new THREE.Color,ja=new THREE.Color,La=Math.PI*2,Y=new THREE.Vector3,na,oa,Ca,ba,pa,
|
||||
va,la=16;na=document.createElement("canvas");na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Ca=oa.getImageData(0,0,2,2);ba=Ca.data;pa=document.createElement("canvas");pa.width=pa.height=la;va=pa.getContext("2d");va.translate(-la/2,-la/2);va.scale(la,la);la--;this.domElement=d;this.autoClear=true;this.setSize=function(fa,wa){f=fa;j=wa;m=f/2;n=j/2;d.width=f;d.height=j;A.set(-m,-n,m,n)};this.clear=function(){if(!V.isEmpty()){V.inflate(1);V.minSelf(A);l.clearRect(V.getX(),
|
||||
V.getY(),V.getWidth(),V.getHeight());V.empty()}};this.render=function(fa,wa){function Ma(s){var U,N,v,F=s.lights;Z.setRGB(0,0,0);ia.setRGB(0,0,0);ja.setRGB(0,0,0);s=0;for(U=F.length;s<U;s++){N=F[s];v=N.color;if(N instanceof THREE.AmbientLight){Z.r+=v.r;Z.g+=v.g;Z.b+=v.b}else if(N instanceof THREE.DirectionalLight){ia.r+=v.r;ia.g+=v.g;ia.b+=v.b}else if(N instanceof THREE.PointLight){ja.r+=v.r;ja.g+=v.g;ja.b+=v.b}}}function xa(s,U,N,v){var F,W,aa,ca,da=s.lights;s=0;for(F=da.length;s<F;s++){W=da[s];
|
||||
aa=W.color;ca=W.intensity;if(W instanceof THREE.DirectionalLight){W=N.dot(W.position)*ca;if(W>0){v.r+=aa.r*W;v.g+=aa.g*W;v.b+=aa.b*W}}else if(W instanceof THREE.PointLight){Y.sub(W.position,U);Y.normalize();W=N.dot(Y)*ca;if(W>0){v.r+=aa.r*W;v.g+=aa.g*W;v.b+=aa.b*W}}}}function Na(s,U,N){if(N.opacity!=0){Da(N.opacity);ya(N.blending);var v,F,W,aa,ca,da;if(N instanceof THREE.ParticleBasicMaterial){if(N.map){aa=N.map;ca=aa.width>>1;da=aa.height>>1;F=U.scale.x*m;W=U.scale.y*n;N=F*ca;v=W*da;X.set(s.x-N,
|
||||
s.y-v,s.x+N,s.y+v);if(A.instersects(X)){l.save();l.translate(s.x,s.y);l.rotate(-U.rotation);l.scale(F,-W);l.translate(-ca,-da);l.drawImage(aa,0,0);l.restore()}}}else if(N instanceof THREE.ParticleCircleMaterial){if(T){R.r=Z.r+ia.r+ja.r;R.g=Z.g+ia.g+ja.g;R.b=Z.b+ia.b+ja.b;h.r=N.color.r*R.r;h.g=N.color.g*R.g;h.b=N.color.b*R.b;h.updateStyleString()}else h.__styleString=N.color.__styleString;N=U.scale.x*m;v=U.scale.y*n;X.set(s.x-N,s.y-v,s.x+N,s.y+v);if(A.instersects(X)){F=h.__styleString;if(C!=F)l.fillStyle=
|
||||
C=F;l.save();l.translate(s.x,s.y);l.rotate(-U.rotation);l.scale(N,v);l.beginPath();l.arc(0,0,1,0,La,true);l.closePath();l.fill();l.restore()}}}}function Oa(s,U,N,v){if(v.opacity!=0){Da(v.opacity);ya(v.blending);l.beginPath();l.moveTo(s.positionScreen.x,s.positionScreen.y);l.lineTo(U.positionScreen.x,U.positionScreen.y);l.closePath();if(v instanceof THREE.LineBasicMaterial){h.__styleString=v.color.__styleString;s=v.linewidth;if(x!=s)l.lineWidth=x=s;s=h.__styleString;if(E!=s)l.strokeStyle=E=s;l.stroke();
|
||||
X.inflate(v.linewidth*2)}}}function Ha(s,U,N,v,F,W){if(F.opacity!=0){Da(F.opacity);ya(F.blending);M=s.positionScreen.x;u=s.positionScreen.y;e=U.positionScreen.x;k=U.positionScreen.y;g=N.positionScreen.x;q=N.positionScreen.y;l.beginPath();l.moveTo(M,u);l.lineTo(e,k);l.lineTo(g,q);l.lineTo(M,u);l.closePath();if(F instanceof THREE.MeshBasicMaterial)if(F.map)F.map.image.loaded&&F.map.mapping instanceof THREE.UVMapping&&qa(M,u,e,k,g,q,F.map.image,v.uvs[0].u,v.uvs[0].v,v.uvs[1].u,v.uvs[1].v,v.uvs[2].u,
|
||||
v.uvs[2].v);else if(F.env_map){if(F.env_map.image.loaded)if(F.env_map.mapping instanceof THREE.SphericalReflectionMapping){s=wa.matrix;Y.copy(v.vertexNormalsWorld[0]);O=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;B=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;Y.copy(v.vertexNormalsWorld[1]);P=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;Q=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;Y.copy(v.vertexNormalsWorld[2]);K=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;y=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;qa(M,u,e,k,g,q,
|
||||
F.env_map.image,O,B,P,Q,K,y)}}else F.wireframe?za(F.color.__styleString,F.wireframe_linewidth):Aa(F.color.__styleString);else if(F instanceof THREE.MeshLambertMaterial){if(F.map&&!F.wireframe){F.map.mapping instanceof THREE.UVMapping&&qa(M,u,e,k,g,q,F.map.image,v.uvs[0].u,v.uvs[0].v,v.uvs[1].u,v.uvs[1].v,v.uvs[2].u,v.uvs[2].v);ya(THREE.SubtractiveBlending)}if(T)if(!F.wireframe&&F.shading==THREE.SmoothShading&&v.vertexNormalsWorld.length==3){i.r=r.r=p.r=Z.r;i.g=r.g=p.g=Z.g;i.b=r.b=p.b=Z.b;xa(W,v.v1.positionWorld,
|
||||
v.vertexNormalsWorld[0],i);xa(W,v.v2.positionWorld,v.vertexNormalsWorld[1],r);xa(W,v.v3.positionWorld,v.vertexNormalsWorld[2],p);D.r=(r.r+p.r)*0.5;D.g=(r.g+p.g)*0.5;D.b=(r.b+p.b)*0.5;t=Ia(i,r,p,D);qa(M,u,e,k,g,q,t,0,0,1,0,0,1)}else{R.r=Z.r;R.g=Z.g;R.b=Z.b;xa(W,v.centroidWorld,v.normalWorld,R);h.r=F.color.r*R.r;h.g=F.color.g*R.g;h.b=F.color.b*R.b;h.updateStyleString();F.wireframe?za(h.__styleString,F.wireframe_linewidth):Aa(h.__styleString)}else F.wireframe?za(F.color.__styleString,F.wireframe_linewidth):
|
||||
Aa(F.color.__styleString)}else if(F instanceof THREE.MeshDepthMaterial){w=F.__2near;I=F.__farPlusNear;S=F.__farMinusNear;i.r=i.g=i.b=1-w/(I-s.positionScreen.z*S);r.r=r.g=r.b=1-w/(I-U.positionScreen.z*S);p.r=p.g=p.b=1-w/(I-N.positionScreen.z*S);D.r=(r.r+p.r)*0.5;D.g=(r.g+p.g)*0.5;D.b=(r.b+p.b)*0.5;t=Ia(i,r,p,D);qa(M,u,e,k,g,q,t,0,0,1,0,0,1)}else if(F instanceof THREE.MeshNormalMaterial){h.r=Ea(v.normalWorld.x);h.g=Ea(v.normalWorld.y);h.b=Ea(v.normalWorld.z);h.updateStyleString();F.wireframe?za(h.__styleString,
|
||||
F.wireframe_linewidth):Aa(h.__styleString)}}}function za(s,U){if(E!=s)l.strokeStyle=E=s;if(x!=U)l.lineWidth=x=U;l.stroke();X.inflate(U*2)}function Aa(s){if(C!=s)l.fillStyle=C=s;l.fill()}function qa(s,U,N,v,F,W,aa,ca,da,ra,ha,sa,ta){var ka,ga;ka=aa.width-1;ga=aa.height-1;ca*=ka;da*=ga;ra*=ka;ha*=ga;sa*=ka;ta*=ga;N-=s;v-=U;F-=s;W-=U;ra-=ca;ha-=da;sa-=ca;ta-=da;ga=1/(ra*ta-sa*ha);ka=(ta*N-ha*F)*ga;ha=(ta*v-ha*W)*ga;N=(ra*F-sa*N)*ga;v=(ra*W-sa*v)*ga;s=s-ka*ca-N*da;U=U-ha*ca-v*da;l.save();l.transform(ka,
|
||||
ha,N,v,s,U);l.clip();l.drawImage(aa,0,0);l.restore()}function Da(s){if(o!=s)l.globalAlpha=o=s}function ya(s){if(c!=s){switch(s){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}c=s}}function Ia(s,U,N,v){ba[0]=H(0,z(255,~~(s.r*255)));ba[1]=H(0,z(255,~~(s.g*255)));ba[2]=H(0,z(255,~~(s.b*255)));ba[4]=H(0,z(255,~~(U.r*255)));ba[5]=H(0,z(255,
|
||||
~~(U.g*255)));ba[6]=H(0,z(255,~~(U.b*255)));ba[8]=H(0,z(255,~~(N.r*255)));ba[9]=H(0,z(255,~~(N.g*255)));ba[10]=H(0,z(255,~~(N.b*255)));ba[12]=H(0,z(255,~~(v.r*255)));ba[13]=H(0,z(255,~~(v.g*255)));ba[14]=H(0,z(255,~~(v.b*255)));oa.putImageData(Ca,0,0);va.drawImage(na,0,0);return pa}function Ea(s){return s<0?z((1+s)*0.5,0.5):0.5+z(s*0.5,0.5)}function Fa(s,U){var N=U.x-s.x,v=U.y-s.y,F=1/Math.sqrt(N*N+v*v);N*=F;v*=F;U.x+=N;U.y+=v;s.x-=N;s.y-=v}var Ba,Ja,$,ea,ma,Ga,Ka,ua;l.setTransform(1,0,0,-1,m,n);
|
||||
this.autoClear&&this.clear();a=b.projectScene(fa,wa);(T=fa.lights.length>0)&&Ma(fa);Ba=0;for(Ja=a.length;Ba<Ja;Ba++){$=a[Ba];X.empty();if($ instanceof THREE.RenderableParticle){G=$;G.x*=m;G.y*=n;ea=0;for(ma=$.material.length;ea<ma;ea++)Na(G,$,$.material[ea],fa)}else if($ instanceof THREE.RenderableLine){G=$.v1;J=$.v2;G.positionScreen.x*=m;G.positionScreen.y*=n;J.positionScreen.x*=m;J.positionScreen.y*=n;X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(J.positionScreen.x,J.positionScreen.y);
|
||||
if(A.instersects(X)){ea=0;for(ma=$.material.length;ea<ma;)Oa(G,J,$,$.material[ea++],fa)}}else if($ instanceof THREE.RenderableFace3){G=$.v1;J=$.v2;L=$.v3;G.positionScreen.x*=m;G.positionScreen.y*=n;J.positionScreen.x*=m;J.positionScreen.y*=n;L.positionScreen.x*=m;L.positionScreen.y*=n;if($.overdraw){Fa(G.positionScreen,J.positionScreen);Fa(J.positionScreen,L.positionScreen);Fa(L.positionScreen,G.positionScreen)}X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(J.positionScreen.x,J.positionScreen.y);
|
||||
X.addPoint(L.positionScreen.x,L.positionScreen.y);if(A.instersects(X)){ea=0;for(ma=$.meshMaterial.length;ea<ma;){ua=$.meshMaterial[ea++];if(ua instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterial.length;Ga<Ka;)(ua=$.faceMaterial[Ga++])&&Ha(G,J,L,$,ua,fa)}else Ha(G,J,L,$,ua,fa)}}}V.addRectangle(X)}l.setTransform(1,0,0,1,0,0)}};
|
||||
THREE.SVGRenderer=function(){function a(B,P,Q){var K,y,A,V;K=0;for(y=B.lights.length;K<y;K++){A=B.lights[K];if(A instanceof THREE.DirectionalLight){V=P.normalWorld.dot(A.position)*A.intensity;if(V>0){Q.r+=A.color.r*V;Q.g+=A.color.g*V;Q.b+=A.color.b*V}}else if(A instanceof THREE.PointLight){i.sub(A.position,P.centroidWorld);i.normalize();V=P.normalWorld.dot(i)*A.intensity;if(V>0){Q.r+=A.color.r*V;Q.g+=A.color.g*V;Q.b+=A.color.b*V}}}}function b(B,P,Q,K,y,A){w=f(I++);w.setAttribute("d","M "+B.positionScreen.x+
|
||||
" "+B.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(y instanceof THREE.MeshBasicMaterial)u.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshLambertMaterial)if(M){e.r=k.r;e.g=k.g;e.b=k.b;a(A,K,e);u.r=y.color.r*e.r;u.g=y.color.g*e.g;u.b=y.color.b*e.b;u.updateStyleString()}else u.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshDepthMaterial){h=1-y.__2near/(y.__farPlusNear-K.z*y.__farMinusNear);
|
||||
u.setRGB(h,h,h)}else y instanceof THREE.MeshNormalMaterial&&u.setRGB(j(K.normalWorld.x),j(K.normalWorld.y),j(K.normalWorld.z));y.wireframe?w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+y.wireframe_linewidth+"; stroke-opacity: "+y.opacity+"; stroke-linecap: "+y.wireframe_linecap+"; stroke-linejoin: "+y.wireframe_linejoin):w.setAttribute("style","fill: "+u.__styleString+"; fill-opacity: "+y.opacity);l.appendChild(w)}function d(B,P,Q,K,y,A,V){w=f(I++);w.setAttribute("d",
|
||||
"M "+B.positionScreen.x+" "+B.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(A instanceof THREE.MeshBasicMaterial)u.__styleString=A.color.__styleString;else if(A instanceof THREE.MeshLambertMaterial)if(M){e.r=k.r;e.g=k.g;e.b=k.b;a(V,y,e);u.r=A.color.r*e.r;u.g=A.color.g*e.g;u.b=A.color.b*e.b;u.updateStyleString()}else u.__styleString=A.color.__styleString;else if(A instanceof THREE.MeshDepthMaterial){h=
|
||||
1-A.__2near/(A.__farPlusNear-y.z*A.__farMinusNear);u.setRGB(h,h,h)}else A instanceof THREE.MeshNormalMaterial&&u.setRGB(j(y.normalWorld.x),j(y.normalWorld.y),j(y.normalWorld.z));A.wireframe?w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+A.wireframe_linewidth+"; stroke-opacity: "+A.opacity+"; stroke-linecap: "+A.wireframe_linecap+"; stroke-linejoin: "+A.wireframe_linejoin):w.setAttribute("style","fill: "+u.__styleString+"; fill-opacity: "+A.opacity);l.appendChild(w)}
|
||||
function f(B){if(r[B]==null){r[B]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&r[B].setAttribute("shape-rendering","crispEdges");return r[B]}return r[B]}function j(B){return B<0?Math.min((1+B)*0.5,0.5):0.5+Math.min(B*0.5,0.5)}var m=null,n=new THREE.Projector,l=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,E,C,x,z,H,G,J=new THREE.Rectangle,L=new THREE.Rectangle,M=false,u=new THREE.Color(16777215),e=new THREE.Color(16777215),k=new THREE.Color(0),g=new THREE.Color(0),
|
||||
q=new THREE.Color(0),h,i=new THREE.Vector3,r=[],p=[],D=[],w,I,S,t,O=1;this.domElement=l;this.autoClear=true;this.setQuality=function(B){switch(B){case "high":O=1;break;case "low":O=0}};this.setSize=function(B,P){o=B;c=P;E=o/2;C=c/2;l.setAttribute("viewBox",-E+" "+-C+" "+o+" "+c);l.setAttribute("width",o);l.setAttribute("height",c);J.set(-E,-C,E,C)};this.clear=function(){for(;l.childNodes.length>0;)l.removeChild(l.childNodes[0])};this.render=function(B,P){var Q,K,y,A,V,X,T,R;this.autoClear&&this.clear();
|
||||
m=n.projectScene(B,P);t=S=I=0;if(M=B.lights.length>0){T=B.lights;k.setRGB(0,0,0);g.setRGB(0,0,0);q.setRGB(0,0,0);Q=0;for(K=T.length;Q<K;Q++){y=T[Q];A=y.color;if(y instanceof THREE.AmbientLight){k.r+=A.r;k.g+=A.g;k.b+=A.b}else if(y instanceof THREE.DirectionalLight){g.r+=A.r;g.g+=A.g;g.b+=A.b}else if(y instanceof THREE.PointLight){q.r+=A.r;q.g+=A.g;q.b+=A.b}}}Q=0;for(K=m.length;Q<K;Q++){T=m[Q];L.empty();if(T instanceof THREE.RenderableParticle){x=T;x.x*=E;x.y*=-C;y=0;for(A=T.material.length;y<A;y++)if(R=
|
||||
T.material[y]){V=x;X=T;R=R;var Z=S++;if(p[Z]==null){p[Z]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&p[Z].setAttribute("shape-rendering","crispEdges")}w=p[Z];w.setAttribute("cx",V.x);w.setAttribute("cy",V.y);w.setAttribute("r",X.scale.x*E);if(R instanceof THREE.ParticleCircleMaterial){if(M){e.r=k.r+g.r+q.r;e.g=k.g+g.g+q.g;e.b=k.b+g.b+q.b;u.r=R.color.r*e.r;u.g=R.color.g*e.g;u.b=R.color.b*e.b;u.updateStyleString()}else u=R.color;w.setAttribute("style","fill: "+u.__styleString)}l.appendChild(w)}}else if(T instanceof
|
||||
THREE.RenderableLine){x=T.v1;z=T.v2;x.positionScreen.x*=E;x.positionScreen.y*=-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);if(J.instersects(L)){y=0;for(A=T.material.length;y<A;)if(R=T.material[y++]){V=x;X=z;R=R;Z=t++;if(D[Z]==null){D[Z]=document.createElementNS("http://www.w3.org/2000/svg","line");O==0&&D[Z].setAttribute("shape-rendering","crispEdges")}w=D[Z];w.setAttribute("x1",V.positionScreen.x);
|
||||
w.setAttribute("y1",V.positionScreen.y);w.setAttribute("x2",X.positionScreen.x);w.setAttribute("y2",X.positionScreen.y);if(R instanceof THREE.LineBasicMaterial){u.__styleString=R.color.__styleString;w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+R.linewidth+"; stroke-opacity: "+R.opacity+"; stroke-linecap: "+R.linecap+"; stroke-linejoin: "+R.linejoin);l.appendChild(w)}}}}else if(T instanceof THREE.RenderableFace3){x=T.v1;z=T.v2;H=T.v3;x.positionScreen.x*=E;x.positionScreen.y*=
|
||||
-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;H.positionScreen.x*=E;H.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);L.addPoint(H.positionScreen.x,H.positionScreen.y);if(J.instersects(L)){y=0;for(A=T.meshMaterial.length;y<A;){R=T.meshMaterial[y++];if(R instanceof THREE.MeshFaceMaterial){V=0;for(X=T.faceMaterial.length;V<X;)(R=T.faceMaterial[V++])&&b(x,z,H,T,R,B)}else R&&b(x,z,H,T,R,B)}}}else if(T instanceof THREE.RenderableFace4){x=
|
||||
T.v1;z=T.v2;H=T.v3;G=T.v4;x.positionScreen.x*=E;x.positionScreen.y*=-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;H.positionScreen.x*=E;H.positionScreen.y*=-C;G.positionScreen.x*=E;G.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);L.addPoint(H.positionScreen.x,H.positionScreen.y);L.addPoint(G.positionScreen.x,G.positionScreen.y);if(J.instersects(L)){y=0;for(A=T.meshMaterial.length;y<A;){R=T.meshMaterial[y++];if(R instanceof
|
||||
THREE.MeshFaceMaterial){V=0;for(X=T.faceMaterial.length;V<X;)(R=T.faceMaterial[V++])&&d(x,z,H,G,T,R,B)}else R&&d(x,z,H,G,T,R,B)}}}}}};
|
||||
THREE.WebGLRenderer=function(a){function b(e,k){var g=c.createProgram(),q=[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(g,n("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+
|
||||
e));c.attachShader(g,n("vertex",q+k));c.linkProgram(g);c.getProgramParameter(g,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(g,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");g.uniforms={};g.attributes={};return g}function d(e,k){if(e.image.length==6){if(!e.image.__webGLTextureCube&&!e.image.__cubeMapInitialized&&e.image.loadCount==6){e.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,e.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 g=0;g<6;++g)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image[g]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_CUBE_MAP,
|
||||
e.image.__webGLTextureCube)}}function f(e,k){if(!e.__webGLTexture&&e.image.loaded){e.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,e.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,l(e.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,l(e.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,l(e.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,l(e.min_filter));c.generateMipmap(c.TEXTURE_2D);
|
||||
c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_2D,e.__webGLTexture)}function j(e,k){var g,q,h;g=0;for(q=k.length;g<q;g++){h=k[g];e.uniforms[h]=c.getUniformLocation(e,h)}}function m(e,k){var g,q,h;g=0;for(q=k.length;g<q;g++){h=k[g];e.attributes[h]=c.getAttribLocation(e,h);e.attributes[h]>=0&&c.enableVertexAttribArray(e.attributes[h])}}function n(e,k){var g;if(e=="fragment")g=c.createShader(c.FRAGMENT_SHADER);else if(e=="vertex")g=c.createShader(c.VERTEX_SHADER);
|
||||
c.shaderSource(g,k);c.compileShader(g);if(!c.getShaderParameter(g,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(g));return null}return g}function l(e){switch(e){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;
|
||||
case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var o=document.createElement("canvas"),c,E,C,x=new THREE.Matrix4,z,H=new Float32Array(16),G=new Float32Array(16),J=new Float32Array(16),L=new Float32Array(9),M=new Float32Array(16);a=function(e,k){if(e){var g,q,h,i=pointLights=maxDirLights=maxPointLights=0;g=0;for(q=e.lights.length;g<q;g++){h=e.lights[g];h instanceof THREE.DirectionalLight&&i++;h instanceof
|
||||
THREE.PointLight&&pointLights++}if(pointLights+i<=k){maxDirLights=i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(k*i/(pointLights+i));maxPointLights=k-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:k-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(u){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);
|
||||
c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);E=C=function(e,k){var g=[e?"#define MAX_DIR_LIGHTS "+e:"",k?"#define MAX_POINT_LIGHTS "+k:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":
|
||||
"",k?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",k?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",k?"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;",
|
||||
e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",k?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",k?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",k?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
||||
"",k?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",k?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",k?"}":"","}\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"),
|
||||
p=[f?"#define MAX_DIR_LIGHTS "+f:"",k?"#define MAX_POINT_LIGHTS "+k:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
||||
f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",k?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
|
||||
q=[e?"#define MAX_DIR_LIGHTS "+e:"",k?"#define MAX_POINT_LIGHTS "+k:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
||||
e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",k?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
|
||||
k?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",k?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",k?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",k?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",k?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",k?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",k?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",k?"float pointSpecularWeight = 0.0;":"",k?"if ( pointDotNormalHalf >= 0.0 )":
|
||||
"",k?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",k?"pointDiffuse += mColor * pointDiffuseWeight;":"",k?"pointSpecular += mSpecular * pointSpecularWeight;":"",k?"}":"",f?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"vec3 dirVector = normalize( lDirection.xyz );":"",f?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
|
||||
"",f?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",f?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",f?"float dirSpecularWeight = 0.0;":"",f?"if ( dirDotNormalHalf >= 0.0 )":"",f?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",f?"dirDiffuse += mColor * dirDiffuseWeight;":"",f?"dirSpecular += mSpecular * dirSpecularWeight;":"",f?"}":"","vec4 totalLight = mAmbient;",f?"totalLight += dirDiffuse + dirSpecular;":"",k?"totalLight += pointDiffuse + pointSpecular;":
|
||||
"",k?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",k?"pointDiffuse += mColor * pointDiffuseWeight;":"",k?"pointSpecular += mSpecular * pointSpecularWeight;":"",k?"}":"",e?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"vec3 dirVector = normalize( lDirection.xyz );":"",e?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
|
||||
"",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",k?"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}"].join("\n");
|
||||
e=b(p,e);c.useProgram(e);j(e,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);f&&j(e,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);k&&j(e,["pointLightNumber","pointLightColor",
|
||||
"pointLightPosition"]);c.uniform1i(e.uniforms.enableMap,0);c.uniform1i(e.uniforms.tMap,0);c.uniform1i(e.uniforms.enableCubeMap,0);c.uniform1i(e.uniforms.tCube,1);c.uniform1i(e.uniforms.mixEnvMap,0);c.uniform1i(e.uniforms.useRefract,0);n(e,["position","normal","uv"]);return e}(a.directional,a.point);this.setSize=function(f,k){o.width=f;o.height=k;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(f,k){var e,p,h,i,s,r=[],
|
||||
M=[],A=[];i=[];s=[];c.uniform1i(f.uniforms.enableLighting,k.length);e=0;for(p=k.length;e<p;e++){h=k[e];if(h instanceof THREE.AmbientLight)r.push(h);else if(h instanceof THREE.DirectionalLight)A.push(h);else h instanceof THREE.PointLight&&M.push(h)}e=h=i=s=0;for(p=r.length;e<p;e++){h+=r[e].color.r;i+=r[e].color.g;s+=r[e].color.b}c.uniform3f(f.uniforms.ambientLightColor,h,i,s);i=[];s=[];e=0;for(p=A.length;e<p;e++){h=A[e];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);
|
||||
s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(A.length){c.uniform1i(f.uniforms.directionalLightNumber,A.length);c.uniform3fv(f.uniforms.directionalLightDirection,s);c.uniform3fv(f.uniforms.directionalLightColor,i)}i=[];s=[];e=0;for(p=M.length;e<p;e++){h=M[e];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(M.length){c.uniform1i(f.uniforms.pointLightNumber,M.length);c.uniform3fv(f.uniforms.pointLightPosition,
|
||||
s);c.uniform3fv(f.uniforms.pointLightColor,i)}};this.createBuffers=function(f,k){var e,p,h,i,s,r,M,A,H=[],Q=[],u=[],R=[],y=[],z=0,E=f.geometry.geometryChunks[k],W;h=false;e=0;for(p=f.material.length;e<p;e++){meshMaterial=f.material[e];if(meshMaterial instanceof THREE.MeshFaceMaterial){s=0;for(W=E.material.length;s<W;s++)if(E.material[s]&&E.material[s].shading!=undefined&&E.material[s].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
|
||||
THREE.SmoothShading){h=true;break}if(h)break}W=h;e=0;for(p=E.faces.length;e<p;e++){h=E.faces[e];i=f.geometry.faces[h];s=i.vertexNormals;faceNormal=i.normal;h=f.geometry.uvs[h];if(i instanceof THREE.Face3){r=f.geometry.vertices[i.a].position;M=f.geometry.vertices[i.b].position;A=f.geometry.vertices[i.c].position;u.push(r.x,r.y,r.z);u.push(M.x,M.y,M.z);u.push(A.x,A.y,A.z);if(s.length==3&&W)for(i=0;i<3;i++)R.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<3;i++)R.push(faceNormal.x,faceNormal.y,faceNormal.z);
|
||||
if(h)for(i=0;i<3;i++)y.push(h[i].u,h[i].v);H.push(z,z+1,z+2);Q.push(z,z+1);Q.push(z,z+2);Q.push(z+1,z+2);z+=3}else if(i instanceof THREE.Face4){r=f.geometry.vertices[i.a].position;M=f.geometry.vertices[i.b].position;A=f.geometry.vertices[i.c].position;i=f.geometry.vertices[i.d].position;u.push(r.x,r.y,r.z);u.push(M.x,M.y,M.z);u.push(A.x,A.y,A.z);u.push(i.x,i.y,i.z);if(s.length==4&&W)for(i=0;i<4;i++)R.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<4;i++)R.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=
|
||||
0;i<4;i++)y.push(h[i].u,h[i].v);H.push(z,z+1,z+2);H.push(z,z+2,z+3);Q.push(z,z+1);Q.push(z,z+2);Q.push(z,z+3);Q.push(z+1,z+2);Q.push(z+2,z+3);z+=4}}if(u.length){E.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(u),c.STATIC_DRAW);E.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(R),c.STATIC_DRAW);if(y.length>0){E.__webGLUVBuffer=c.createBuffer();
|
||||
c.bindBuffer(c.ARRAY_BUFFER,E.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(y),c.STATIC_DRAW)}E.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(H),c.STATIC_DRAW);E.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);E.__webGLFaceCount=H.length;E.__webGLLineCount=Q.length}};this.renderBuffer=
|
||||
function(f,k,e,p){var h,i,s,r,M,A,H,Q,u;if(e instanceof THREE.MeshShaderMaterial){if(!e.program){e.program=b(e.fragment_shader,e.vertex_shader);H=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(u in e.uniforms)H.push(u);j(e.program,H);n(e.program,["position","normal","uv"])}u=e.program}else u=D;if(u!=F){c.useProgram(u);F=u}u==D&&this.setupLights(u,k);this.loadCamera(u,f);this.loadMatrices(u);if(e instanceof THREE.MeshShaderMaterial){s=e.wireframe;
|
||||
r=e.wireframe_linewidth;f=u;k=e.uniforms;var R;for(h in k){Q=k[h].type;H=k[h].value;R=f.uniforms[h];if(Q=="i")c.uniform1i(R,H);else if(Q=="f")c.uniform1f(R,H);else if(Q=="v3")c.uniform3f(R,H.x,H.y,H.z);else if(Q=="c")c.uniform3f(R,H.r,H.g,H.b);else if(Q=="t"){c.uniform1i(R,H);if(Q=k[h].texture)Q.image instanceof Array&&Q.image.length==6?d(Q,H):g(Q,H)}}}if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=e.color;i=e.opacity;s=e.wireframe;
|
||||
r=e.wireframe_linewidth;M=e.map;A=e.env_map;k=e.combine==THREE.MixOperation;f=e.reflectivity;Q=e.env_map&&e.env_map.mapping instanceof THREE.CubeRefractionMapping;H=e.refraction_ratio;c.uniform4f(u.uniforms.mColor,h.r*i,h.g*i,h.b*i,i);c.uniform1i(u.uniforms.mixEnvMap,k);c.uniform1f(u.uniforms.mReflectivity,f);c.uniform1i(u.uniforms.useRefract,Q);c.uniform1f(u.uniforms.mRefractionRatio,H)}if(e instanceof THREE.MeshNormalMaterial){i=e.opacity;c.uniform1f(u.uniforms.mOpacity,i);c.uniform1i(u.uniforms.material,
|
||||
4)}else if(e instanceof THREE.MeshDepthMaterial){i=e.opacity;s=e.wireframe;r=e.wireframe_linewidth;c.uniform1f(u.uniforms.mOpacity,i);c.uniform1f(u.uniforms.m2Near,e.__2near);c.uniform1f(u.uniforms.mFarPlusNear,e.__farPlusNear);c.uniform1f(u.uniforms.mFarMinusNear,e.__farMinusNear);c.uniform1i(u.uniforms.material,3)}else if(e instanceof THREE.MeshPhongMaterial){h=e.ambient;f=e.specular;e=e.shininess;c.uniform4f(u.uniforms.mAmbient,h.r,h.g,h.b,i);c.uniform4f(u.uniforms.mSpecular,f.r,f.g,f.b,i);c.uniform1f(u.uniforms.mShininess,
|
||||
e);c.uniform1i(u.uniforms.material,2)}else if(e instanceof THREE.MeshLambertMaterial)c.uniform1i(u.uniforms.material,1);else if(e instanceof THREE.MeshBasicMaterial)c.uniform1i(u.uniforms.material,0);else if(e instanceof THREE.MeshCubeMaterial){c.uniform1i(u.uniforms.material,5);A=e.env_map}if(M){g(M,0);c.uniform1i(u.uniforms.tMap,0);c.uniform1i(u.uniforms.enableMap,1)}else c.uniform1i(u.uniforms.enableMap,0);if(A){d(A,1);c.uniform1i(u.uniforms.tCube,1);c.uniform1i(u.uniforms.enableCubeMap,1)}else c.uniform1i(u.uniforms.enableCubeMap,
|
||||
0);i=u.attributes;c.bindBuffer(c.ARRAY_BUFFER,p.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,p.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.uv>=0)if(p.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(s){c.lineWidth(r);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLLineBuffer);
|
||||
c.drawElements(c.LINES,p.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,p.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(f,k,e,p,h,i){var s,r,M,A,H;M=0;for(A=e.material.length;M<A;M++){s=e.material[M];if(s instanceof THREE.MeshFaceMaterial){s=0;for(r=p.material.length;s<r;s++)if((H=p.material[s])&&H.blending==h&&H.opacity<1==i){this.setBlending(H.blending);this.renderBuffer(f,k,H,p)}}else if((H=s)&&H.blending==
|
||||
h&&H.opacity<1==i){this.setBlending(H.blending);this.renderBuffer(f,k,H,p)}}};this.render=function(f,k){var e,p,h,i,s=f.lights;this.initWebGLObjects(f);this.autoClear&&this.clear();k.autoUpdateMatrix&&k.updateMatrix();e=0;for(p=f.__webGLObjects.length;e<p;e++){h=f.__webGLObjects[e];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,k);this.renderPass(k,s,i,h,THREE.NormalBlending,false)}}e=0;for(p=f.__webGLObjects.length;e<p;e++){h=f.__webGLObjects[e];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,
|
||||
k);this.renderPass(k,s,i,h,THREE.AdditiveBlending,false);this.renderPass(k,s,i,h,THREE.SubtractiveBlending,false);this.renderPass(k,s,i,h,THREE.AdditiveBlending,true);this.renderPass(k,s,i,h,THREE.SubtractiveBlending,true);this.renderPass(k,s,i,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(f){var k,e,p,h,i,s;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={}}k=0;for(e=f.objects.length;k<e;k++){p=f.objects[k];if(f.__webGLObjectsMap[p.id]==undefined)f.__webGLObjectsMap[p.id]=
|
||||
{};s=f.__webGLObjectsMap[p.id];if(p instanceof THREE.Mesh)for(i in p.geometry.geometryChunks){h=p.geometry.geometryChunks[i];h.__webGLVertexBuffer||this.createBuffers(p,i);if(s[i]==undefined){h={buffer:h,object:p};f.__webGLObjects.push(h);s[i]=1}}}};this.removeObject=function(f,k){var e,p;for(e=f.__webGLObjects.length-1;e>=0;e--){p=f.__webGLObjects[e].object;k==p&&f.__webGLObjects.splice(e,1)}};this.setupMatrices=function(f,k){f.autoUpdateMatrix&&f.updateMatrix();w.multiply(k.matrix,f.matrix);I.set(k.matrix.flatten());
|
||||
G.set(w.flatten());L.set(k.projectionMatrix.flatten());x=THREE.Matrix4.makeInvert3x3(w).transpose();N.set(x.m);O.set(f.matrix.flatten())};this.loadMatrices=function(f){c.uniformMatrix4fv(f.uniforms.viewMatrix,false,I);c.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,G);c.uniformMatrix4fv(f.uniforms.projectionMatrix,false,L);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,N);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,O)};this.loadCamera=function(f,k){c.uniform3f(f.uniforms.cameraPosition,
|
||||
k.position.x,k.position.y,k.position.z)};this.setBlending=function(f){switch(f){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(f,k){if(f){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(f=="back")c.cullFace(c.BACK);else f=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);
|
||||
c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};
|
||||
THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
|
||||
g=b(q,g);c.useProgram(g);j(g,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);e&&j(g,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);k&&j(g,["pointLightNumber","pointLightColor",
|
||||
"pointLightPosition"]);c.uniform1i(g.uniforms.enableMap,0);c.uniform1i(g.uniforms.tMap,0);c.uniform1i(g.uniforms.enableCubeMap,0);c.uniform1i(g.uniforms.tCube,1);c.uniform1i(g.uniforms.mixEnvMap,0);c.uniform1i(g.uniforms.useRefract,0);m(g,["position","normal","uv"]);return g}(a.directional,a.point);this.setSize=function(e,k){o.width=e;o.height=k;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,k){var g,q,h,i,r,p=[],
|
||||
D=[],w=[];i=[];r=[];c.uniform1i(e.uniforms.enableLighting,k.length);g=0;for(q=k.length;g<q;g++){h=k[g];if(h instanceof THREE.AmbientLight)p.push(h);else if(h instanceof THREE.DirectionalLight)w.push(h);else h instanceof THREE.PointLight&&D.push(h)}g=h=i=r=0;for(q=p.length;g<q;g++){h+=p[g].color.r;i+=p[g].color.g;r+=p[g].color.b}c.uniform3f(e.uniforms.ambientLightColor,h,i,r);i=[];r=[];g=0;for(q=w.length;g<q;g++){h=w[g];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);
|
||||
r.push(h.position.x);r.push(h.position.y);r.push(h.position.z)}if(w.length){c.uniform1i(e.uniforms.directionalLightNumber,w.length);c.uniform3fv(e.uniforms.directionalLightDirection,r);c.uniform3fv(e.uniforms.directionalLightColor,i)}i=[];r=[];g=0;for(q=D.length;g<q;g++){h=D[g];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);r.push(h.position.x);r.push(h.position.y);r.push(h.position.z)}if(D.length){c.uniform1i(e.uniforms.pointLightNumber,D.length);c.uniform3fv(e.uniforms.pointLightPosition,
|
||||
r);c.uniform3fv(e.uniforms.pointLightColor,i)}};this.createBuffers=function(e,k){var g,q,h,i,r,p,D,w,I,S=[],t=[],O=[],B=[],P=[],Q=[],K=0,y=e.geometry.geometryChunks[k],A;h=false;g=0;for(q=e.material.length;g<q;g++){meshMaterial=e.material[g];if(meshMaterial instanceof THREE.MeshFaceMaterial){r=0;for(A=y.material.length;r<A;r++)if(y.material[r]&&y.material[r].shading!=undefined&&y.material[r].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
|
||||
THREE.SmoothShading){h=true;break}if(h)break}A=h;g=0;for(q=y.faces.length;g<q;g++){h=y.faces[g];i=e.geometry.faces[h];r=i.vertexNormals;faceNormal=i.normal;h=e.geometry.uvs[h];if(i instanceof THREE.Face3){p=e.geometry.vertices[i.a].position;D=e.geometry.vertices[i.b].position;w=e.geometry.vertices[i.c].position;O.push(p.x,p.y,p.z);O.push(D.x,D.y,D.z);O.push(w.x,w.y,w.z);if(e.geometry.hasTangents){p=e.geometry.vertices[i.a].tangent;D=e.geometry.vertices[i.b].tangent;w=e.geometry.vertices[i.c].tangent;
|
||||
P.push(p.x,p.y,p.z,p.w);P.push(D.x,D.y,D.z,D.w);P.push(w.x,w.y,w.z,w.w)}if(r.length==3&&A)for(i=0;i<3;i++)B.push(r[i].x,r[i].y,r[i].z);else for(i=0;i<3;i++)B.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=0;i<3;i++)Q.push(h[i].u,h[i].v);S.push(K,K+1,K+2);t.push(K,K+1);t.push(K,K+2);t.push(K+1,K+2);K+=3}else if(i instanceof THREE.Face4){p=e.geometry.vertices[i.a].position;D=e.geometry.vertices[i.b].position;w=e.geometry.vertices[i.c].position;I=e.geometry.vertices[i.d].position;O.push(p.x,
|
||||
p.y,p.z);O.push(D.x,D.y,D.z);O.push(w.x,w.y,w.z);O.push(I.x,I.y,I.z);if(e.geometry.hasTangents){p=e.geometry.vertices[i.a].tangent;D=e.geometry.vertices[i.b].tangent;w=e.geometry.vertices[i.c].tangent;i=e.geometry.vertices[i.d].tangent;P.push(p.x,p.y,p.z,p.w);P.push(D.x,D.y,D.z,D.w);P.push(w.x,w.y,w.z,w.w);P.push(i.x,i.y,i.z,i.w)}if(r.length==4&&A)for(i=0;i<4;i++)B.push(r[i].x,r[i].y,r[i].z);else for(i=0;i<4;i++)B.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=0;i<4;i++)Q.push(h[i].u,h[i].v);
|
||||
S.push(K,K+1,K+2);S.push(K,K+2,K+3);t.push(K,K+1);t.push(K,K+2);t.push(K,K+3);t.push(K+1,K+2);t.push(K+2,K+3);K+=4}}if(O.length){y.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW);y.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(B),c.STATIC_DRAW);if(e.geometry.hasTangents){y.__webGLTangentBuffer=c.createBuffer();
|
||||
c.bindBuffer(c.ARRAY_BUFFER,y.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(P),c.STATIC_DRAW)}if(Q.length>0){y.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(Q),c.STATIC_DRAW)}y.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(S),c.STATIC_DRAW);y.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
|
||||
y.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(t),c.STATIC_DRAW);y.__webGLFaceCount=S.length;y.__webGLLineCount=t.length}};this.renderBuffer=function(e,k,g,q){var h,i,r,p,D,w,I,S,t;if(g instanceof THREE.MeshShaderMaterial){if(!g.program){g.program=b(g.fragment_shader,g.vertex_shader);I=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(t in g.uniforms)I.push(t);j(g.program,I);m(g.program,["position","normal","uv","tangent"])}t=
|
||||
g.program}else t=C;if(t!=E){c.useProgram(t);E=t}t==C&&this.setupLights(t,k);this.loadCamera(t,e);this.loadMatrices(t);if(g instanceof THREE.MeshShaderMaterial){r=g.wireframe;p=g.wireframe_linewidth;e=t;k=g.uniforms;var O;for(h in k){S=k[h].type;I=k[h].value;O=e.uniforms[h];if(S=="i")c.uniform1i(O,I);else if(S=="f")c.uniform1f(O,I);else if(S=="v3")c.uniform3f(O,I.x,I.y,I.z);else if(S=="c")c.uniform3f(O,I.r,I.g,I.b);else if(S=="t"){c.uniform1i(O,I);if(S=k[h].texture)S.image instanceof Array&&S.image.length==
|
||||
6?d(S,I):f(S,I)}}}if(g instanceof THREE.MeshPhongMaterial||g instanceof THREE.MeshLambertMaterial||g instanceof THREE.MeshBasicMaterial){h=g.color;i=g.opacity;r=g.wireframe;p=g.wireframe_linewidth;D=g.map;w=g.env_map;k=g.combine==THREE.MixOperation;e=g.reflectivity;S=g.env_map&&g.env_map.mapping instanceof THREE.CubeRefractionMapping;I=g.refraction_ratio;c.uniform4f(t.uniforms.mColor,h.r*i,h.g*i,h.b*i,i);c.uniform1i(t.uniforms.mixEnvMap,k);c.uniform1f(t.uniforms.mReflectivity,e);c.uniform1i(t.uniforms.useRefract,
|
||||
S);c.uniform1f(t.uniforms.mRefractionRatio,I)}if(g instanceof THREE.MeshNormalMaterial){i=g.opacity;c.uniform1f(t.uniforms.mOpacity,i);c.uniform1i(t.uniforms.material,4)}else if(g instanceof THREE.MeshDepthMaterial){i=g.opacity;r=g.wireframe;p=g.wireframe_linewidth;c.uniform1f(t.uniforms.mOpacity,i);c.uniform1f(t.uniforms.m2Near,g.__2near);c.uniform1f(t.uniforms.mFarPlusNear,g.__farPlusNear);c.uniform1f(t.uniforms.mFarMinusNear,g.__farMinusNear);c.uniform1i(t.uniforms.material,3)}else if(g instanceof
|
||||
THREE.MeshPhongMaterial){h=g.ambient;e=g.specular;g=g.shininess;c.uniform4f(t.uniforms.mAmbient,h.r,h.g,h.b,i);c.uniform4f(t.uniforms.mSpecular,e.r,e.g,e.b,i);c.uniform1f(t.uniforms.mShininess,g);c.uniform1i(t.uniforms.material,2)}else if(g instanceof THREE.MeshLambertMaterial)c.uniform1i(t.uniforms.material,1);else if(g instanceof THREE.MeshBasicMaterial)c.uniform1i(t.uniforms.material,0);else if(g instanceof THREE.MeshCubeMaterial){c.uniform1i(t.uniforms.material,5);w=g.env_map}if(D){f(D,0);c.uniform1i(t.uniforms.tMap,
|
||||
0);c.uniform1i(t.uniforms.enableMap,1)}else c.uniform1i(t.uniforms.enableMap,0);if(w){d(w,1);c.uniform1i(t.uniforms.tCube,1);c.uniform1i(t.uniforms.enableCubeMap,1)}else c.uniform1i(t.uniforms.enableCubeMap,0);i=t.attributes;c.bindBuffer(c.ARRAY_BUFFER,q.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,q.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLTangentBuffer);
|
||||
c.vertexAttribPointer(i.tangent,4,c.FLOAT,false,0,0)}if(i.uv>=0)if(q.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(r){c.lineWidth(p);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);c.drawElements(c.LINES,q.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,q.__webGLFaceCount,c.UNSIGNED_SHORT,
|
||||
0)}};this.renderPass=function(e,k,g,q,h,i){var r,p,D,w,I;D=0;for(w=g.material.length;D<w;D++){r=g.material[D];if(r instanceof THREE.MeshFaceMaterial){r=0;for(p=q.material.length;r<p;r++)if((I=q.material[r])&&I.blending==h&&I.opacity<1==i){this.setBlending(I.blending);this.renderBuffer(e,k,I,q)}}else if((I=r)&&I.blending==h&&I.opacity<1==i){this.setBlending(I.blending);this.renderBuffer(e,k,I,q)}}};this.render=function(e,k){var g,q,h,i,r=e.lights;this.initWebGLObjects(e);this.autoClear&&this.clear();
|
||||
k.autoUpdateMatrix&&k.updateMatrix();g=0;for(q=e.__webGLObjects.length;g<q;g++){h=e.__webGLObjects[g];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,k);this.renderPass(k,r,i,h,THREE.NormalBlending,false)}}g=0;for(q=e.__webGLObjects.length;g<q;g++){h=e.__webGLObjects[g];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,k);this.renderPass(k,r,i,h,THREE.AdditiveBlending,false);this.renderPass(k,r,i,h,THREE.SubtractiveBlending,false);this.renderPass(k,r,i,h,THREE.AdditiveBlending,true);
|
||||
this.renderPass(k,r,i,h,THREE.SubtractiveBlending,true);this.renderPass(k,r,i,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var k,g,q,h,i,r;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}k=0;for(g=e.objects.length;k<g;k++){q=e.objects[k];if(e.__webGLObjectsMap[q.id]==undefined)e.__webGLObjectsMap[q.id]={};r=e.__webGLObjectsMap[q.id];if(q instanceof THREE.Mesh)for(i in q.geometry.geometryChunks){h=q.geometry.geometryChunks[i];h.__webGLVertexBuffer||this.createBuffers(q,
|
||||
i);if(r[i]==undefined){h={buffer:h,object:q};e.__webGLObjects.push(h);r[i]=1}}}};this.removeObject=function(e,k){var g,q;for(g=e.__webGLObjects.length-1;g>=0;g--){q=e.__webGLObjects[g].object;k==q&&e.__webGLObjects.splice(g,1)}};this.setupMatrices=function(e,k){e.autoUpdateMatrix&&e.updateMatrix();x.multiply(k.matrix,e.matrix);H.set(k.matrix.flatten());G.set(x.flatten());J.set(k.projectionMatrix.flatten());z=THREE.Matrix4.makeInvert3x3(x).transpose();L.set(z.m);M.set(e.matrix.flatten())};this.loadMatrices=
|
||||
function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,H);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,G);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,J);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,L);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,M)};this.loadCamera=function(e,k){c.uniform3f(e.uniforms.cameraPosition,k.position.x,k.position.y,k.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);
|
||||
break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,k){if(e){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);else e=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
|
||||
THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
|
||||
THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
|
||||
|
||||
+121
-116
@@ -5,59 +5,62 @@ THREE.Color.prototype={setRGB:function(a,b,d){this.r=a;this.g=b;this.b=d;if(this
|
||||
THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},unit:function(){this.multiplyScalar(1/this.length());return this},length:function(){return Math.sqrt(this.x*
|
||||
this.x+this.y*this.y)},lengthSq:function(){return this.x*this.x+this.y*this.y},negate:function(){this.x=-this.x;this.y=-this.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},toString:function(){return"THREE.Vector2 ("+this.x+", "+this.y+")"}};THREE.Vector3=function(a,b,d){this.x=a||0;this.y=b||0;this.z=d||0};
|
||||
THREE.Vector3.prototype={set:function(a,b,d){this.x=a;this.y=b;this.z=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
|
||||
cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,g=this.z;this.x=d*a.z-g*a.y;this.y=g*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
|
||||
cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,f=this.z;this.x=d*a.z-f*a.y;this.y=f*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
|
||||
a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+d*d+a*a)},distanceToSquared:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return b*b+d*d+a*a},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},negate:function(){this.x=-this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=
|
||||
Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<1.0E-4&&Math.abs(this.y)<1.0E-4&&Math.abs(this.z)<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},toString:function(){return"THREE.Vector3 ( "+this.x+", "+this.y+", "+this.z+" )"}};
|
||||
THREE.Vector4=function(a,b,d,g){this.x=a||0;this.y=b||0;this.z=d||0;this.w=g||1};
|
||||
THREE.Vector4.prototype={set:function(a,b,d,g){this.x=a;this.y=b;this.z=d;this.w=g;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;
|
||||
THREE.Vector4=function(a,b,d,f){this.x=a||0;this.y=b||0;this.z=d||0;this.w=f||1};
|
||||
THREE.Vector4.prototype={set:function(a,b,d,f){this.x=a;this.y=b;this.z=d;this.w=f;return this},copy:function(a){this.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,d,g=a.objects,j=[];a=0;for(b=g.length;a<b;a++){d=g[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(n,m){return n.distance-m.distance});return j},intersectObject:function(a){function b(L,N,O,v){v=v.clone().subSelf(N);O=O.clone().subSelf(N);var f=L.clone().subSelf(N);L=v.dot(v);N=v.dot(O);v=v.dot(f);var l=O.dot(O);O=O.dot(f);f=1/(L*l-N*N);l=(l*v-N*O)*f;L=(L*O-N*v)*f;return l>0&&L>0&&l+L<1}var d,g,j,n,m,k,o,c,F,D,
|
||||
w,x=a.geometry,I=x.vertices,G=[];d=0;for(g=x.faces.length;d<g;d++){j=x.faces[d];D=this.origin.clone();w=this.direction.clone();n=a.matrix.multiplyVector3(I[j.a].position.clone());m=a.matrix.multiplyVector3(I[j.b].position.clone());k=a.matrix.multiplyVector3(I[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(I[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());F=w.dot(c);if(F<0){c=c.dot((new THREE.Vector3).sub(n,D))/F;D=D.addSelf(w.multiplyScalar(c));
|
||||
if(j instanceof THREE.Face3){if(b(D,n,m,k)){j={distance:this.origin.distanceTo(D),point:D,face:j,object:a};G.push(j)}}else if(j instanceof THREE.Face4)if(b(D,n,m,o)||b(D,m,k,o)){j={distance:this.origin.distanceTo(D),point:D,face:j,object:a};G.push(j)}}}return G}};
|
||||
THREE.Rectangle=function(){function a(){n=g-b;m=j-d}var b,d,g,j,n,m,k=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return n};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return g};this.getBottom=function(){return j};this.set=function(o,c,F,D){k=false;b=o;d=c;g=F;j=D;a()};this.addPoint=function(o,c){if(k){k=false;b=o;d=c;g=o;j=c}else{b=Math.min(b,o);d=Math.min(d,c);g=Math.max(g,
|
||||
o);j=Math.max(j,c)}a()};this.addRectangle=function(o){if(k){k=false;b=o.getLeft();d=o.getTop();g=o.getRight();j=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());g=Math.max(g,o.getRight());j=Math.max(j,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;g+=o;j+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());g=Math.min(g,o.getRight());j=Math.min(j,o.getBottom());a()};this.instersects=function(o){return Math.min(g,o.getRight())-Math.max(b,o.getLeft())>=
|
||||
0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){k=true;j=g=d=b=0;a()};this.isEmpty=function(){return k};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+g+", top: "+d+", bottom: "+j+", width: "+n+", height: "+m+" )"}};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.Ray.prototype={intersectScene:function(a){var b,d,f=a.objects,j=[];a=0;for(b=f.length;a<b;a++){d=f[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(m,n){return m.distance-n.distance});return j},intersectObject:function(a){function b(J,L,M,u){u=u.clone().subSelf(L);M=M.clone().subSelf(L);var e=J.clone().subSelf(L);J=u.dot(u);L=u.dot(M);u=u.dot(e);var l=M.dot(M);M=M.dot(e);e=1/(J*l-L*L);l=(l*u-L*M)*e;J=(J*M-L*u)*e;return l>0&&J>0&&l+J<1}var d,f,j,m,n,k,o,c,E,C,
|
||||
x,z=a.geometry,H=z.vertices,G=[];d=0;for(f=z.faces.length;d<f;d++){j=z.faces[d];C=this.origin.clone();x=this.direction.clone();m=a.matrix.multiplyVector3(H[j.a].position.clone());n=a.matrix.multiplyVector3(H[j.b].position.clone());k=a.matrix.multiplyVector3(H[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(H[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());E=x.dot(c);if(E<0){c=c.dot((new THREE.Vector3).sub(m,C))/E;C=C.addSelf(x.multiplyScalar(c));
|
||||
if(j instanceof THREE.Face3){if(b(C,m,n,k)){j={distance:this.origin.distanceTo(C),point:C,face:j,object:a};G.push(j)}}else if(j instanceof THREE.Face4)if(b(C,m,n,o)||b(C,n,k,o)){j={distance:this.origin.distanceTo(C),point:C,face:j,object:a};G.push(j)}}}return G}};
|
||||
THREE.Rectangle=function(){function a(){m=f-b;n=j-d}var b,d,f,j,m,n,k=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return m};this.getHeight=function(){return n};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return f};this.getBottom=function(){return j};this.set=function(o,c,E,C){k=false;b=o;d=c;f=E;j=C;a()};this.addPoint=function(o,c){if(k){k=false;b=o;d=c;f=o;j=c}else{b=Math.min(b,o);d=Math.min(d,c);f=Math.max(f,
|
||||
o);j=Math.max(j,c)}a()};this.addRectangle=function(o){if(k){k=false;b=o.getLeft();d=o.getTop();f=o.getRight();j=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());f=Math.max(f,o.getRight());j=Math.max(j,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;f+=o;j+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());f=Math.min(f,o.getRight());j=Math.min(j,o.getBottom());a()};this.instersects=function(o){return Math.min(f,o.getRight())-Math.max(b,o.getLeft())>=
|
||||
0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){k=true;j=f=d=b=0;a()};this.isEmpty=function(){return k};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+f+", top: "+d+", bottom: "+j+", width: "+m+", height: "+n+" )"}};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(){};
|
||||
THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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},lookAt:function(a,b,d){var g=new THREE.Vector3,j=new THREE.Vector3,n=new THREE.Vector3;n.sub(a,b).normalize();g.cross(d,n).normalize();j.cross(n,g).normalize();this.n11=g.x;this.n12=g.y;this.n13=g.z;this.n14=-g.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=n.x;this.n32=n.y;this.n33=n.z;this.n34=-n.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,g=a.z,j=1/(this.n41*b+this.n42*
|
||||
d+this.n43*g+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*g+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*g+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*g+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,g=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*g+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*g+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*g+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*g+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
|
||||
a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,g=a.n12,j=a.n13,n=a.n14,m=a.n21,k=a.n22,o=a.n23,c=a.n24,F=a.n31,D=a.n32,w=a.n33,x=a.n34,I=a.n41,G=a.n42,L=a.n43,N=a.n44,O=b.n11,v=b.n12,f=b.n13,l=b.n14,e=b.n21,q=b.n22,h=b.n23,i=b.n24,s=b.n31,r=b.n32,M=b.n33,B=b.n34,H=b.n41,Q=b.n42,u=b.n43,
|
||||
R=b.n44;this.n11=d*O+g*e+j*s+n*H;this.n12=d*v+g*q+j*r+n*Q;this.n13=d*f+g*h+j*M+n*u;this.n14=d*l+g*i+j*B+n*R;this.n21=m*O+k*e+o*s+c*H;this.n22=m*v+k*q+o*r+c*Q;this.n23=m*f+k*h+o*M+c*u;this.n24=m*l+k*i+o*B+c*R;this.n31=F*O+D*e+w*s+x*H;this.n32=F*v+D*q+w*r+x*Q;this.n33=F*f+D*h+w*M+x*u;this.n34=F*l+D*i+w*B+x*R;this.n41=I*O+G*e+L*s+N*H;this.n42=I*v+G*q+L*r+N*Q;this.n43=I*f+G*h+L*M+N*u;this.n44=I*l+G*i+L*B+N*R},multiplySelf:function(a){var b=this.n11,d=this.n12,g=this.n13,j=this.n14,n=this.n21,m=this.n22,
|
||||
k=this.n23,o=this.n24,c=this.n31,F=this.n32,D=this.n33,w=this.n34,x=this.n41,I=this.n42,G=this.n43,L=this.n44;this.n11=b*a.n11+d*a.n21+g*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+g*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+g*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+g*a.n34+j*a.n44;this.n21=n*a.n11+m*a.n21+k*a.n31+o*a.n41;this.n22=n*a.n12+m*a.n22+k*a.n32+o*a.n42;this.n23=n*a.n13+m*a.n23+k*a.n33+o*a.n43;this.n24=n*a.n14+m*a.n24+k*a.n34+o*a.n44;this.n31=c*a.n11+F*a.n21+D*a.n31+w*a.n41;this.n32=c*a.n12+F*a.n22+
|
||||
D*a.n32+w*a.n42;this.n33=c*a.n13+F*a.n23+D*a.n33+w*a.n43;this.n34=c*a.n14+F*a.n24+D*a.n34+w*a.n44;this.n41=x*a.n11+I*a.n21+G*a.n31+L*a.n41;this.n42=x*a.n12+I*a.n22+G*a.n32+L*a.n42;this.n43=x*a.n13+I*a.n23+G*a.n33+L*a.n43;this.n44=x*a.n14+I*a.n24+G*a.n34+L*a.n44},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},determinant:function(){return this.n14*
|
||||
a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44},lookAt:function(a,b,d){var f=new THREE.Vector3,j=new THREE.Vector3,m=new THREE.Vector3;m.sub(a,b).normalize();f.cross(d,m).normalize();j.cross(m,f).normalize();this.n11=f.x;this.n12=f.y;this.n13=f.z;this.n14=-f.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=m.x;this.n32=m.y;this.n33=m.z;this.n34=-m.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,f=a.z,j=1/(this.n41*b+this.n42*
|
||||
d+this.n43*f+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*f+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*f+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*f+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,f=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*f+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*f+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*f+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*f+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
|
||||
a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,f=a.n12,j=a.n13,m=a.n14,n=a.n21,k=a.n22,o=a.n23,c=a.n24,E=a.n31,C=a.n32,x=a.n33,z=a.n34,H=a.n41,G=a.n42,J=a.n43,L=a.n44,M=b.n11,u=b.n12,e=b.n13,l=b.n14,g=b.n21,q=b.n22,h=b.n23,i=b.n24,s=b.n31,p=b.n32,D=b.n33,w=b.n34,I=b.n41,S=b.n42,t=b.n43,
|
||||
O=b.n44;this.n11=d*M+f*g+j*s+m*I;this.n12=d*u+f*q+j*p+m*S;this.n13=d*e+f*h+j*D+m*t;this.n14=d*l+f*i+j*w+m*O;this.n21=n*M+k*g+o*s+c*I;this.n22=n*u+k*q+o*p+c*S;this.n23=n*e+k*h+o*D+c*t;this.n24=n*l+k*i+o*w+c*O;this.n31=E*M+C*g+x*s+z*I;this.n32=E*u+C*q+x*p+z*S;this.n33=E*e+C*h+x*D+z*t;this.n34=E*l+C*i+x*w+z*O;this.n41=H*M+G*g+J*s+L*I;this.n42=H*u+G*q+J*p+L*S;this.n43=H*e+G*h+J*D+L*t;this.n44=H*l+G*i+J*w+L*O},multiplySelf:function(a){var b=this.n11,d=this.n12,f=this.n13,j=this.n14,m=this.n21,n=this.n22,
|
||||
k=this.n23,o=this.n24,c=this.n31,E=this.n32,C=this.n33,x=this.n34,z=this.n41,H=this.n42,G=this.n43,J=this.n44;this.n11=b*a.n11+d*a.n21+f*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+f*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+f*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+f*a.n34+j*a.n44;this.n21=m*a.n11+n*a.n21+k*a.n31+o*a.n41;this.n22=m*a.n12+n*a.n22+k*a.n32+o*a.n42;this.n23=m*a.n13+n*a.n23+k*a.n33+o*a.n43;this.n24=m*a.n14+n*a.n24+k*a.n34+o*a.n44;this.n31=c*a.n11+E*a.n21+C*a.n31+x*a.n41;this.n32=c*a.n12+E*a.n22+
|
||||
C*a.n32+x*a.n42;this.n33=c*a.n13+E*a.n23+C*a.n33+x*a.n43;this.n34=c*a.n14+E*a.n24+C*a.n34+x*a.n44;this.n41=z*a.n11+H*a.n21+G*a.n31+J*a.n41;this.n42=z*a.n12+H*a.n22+G*a.n32+J*a.n42;this.n43=z*a.n13+H*a.n23+G*a.n33+J*a.n43;this.n44=z*a.n14+H*a.n24+G*a.n34+J*a.n44},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},determinant:function(){return this.n14*
|
||||
this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
|
||||
this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,g){var j=b[d];b[d]=b[g];b[g]=j}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
|
||||
this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,f){var j=b[d];b[d]=b[f];b[f]=j}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
|
||||
"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){return[this.n11,this.n21,this.n31,this.n41,this.n12,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
|
||||
toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var g=new THREE.Matrix4;g.n14=a;g.n24=b;g.n34=d;return g};THREE.Matrix4.scaleMatrix=function(a,b,d){var g=new THREE.Matrix4;g.n11=a;g.n22=b;g.n33=d;return g};
|
||||
toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var f=new THREE.Matrix4;f.n14=a;f.n24=b;f.n34=d;return f};THREE.Matrix4.scaleMatrix=function(a,b,d){var f=new THREE.Matrix4;f.n11=a;f.n22=b;f.n33=d;return f};
|
||||
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 d=new THREE.Matrix4,g=Math.cos(b),j=Math.sin(b),n=1-g,m=a.x,k=a.y,o=a.z;d.n11=n*m*m+g;d.n12=n*m*k-j*o;d.n13=n*m*o+j*k;d.n21=n*m*k+j*o;d.n22=n*k*k+g;d.n23=n*k*o-j*m;d.n31=n*m*o-j*k;d.n32=n*k*o+j*m;d.n33=n*o*o+g;return d};
|
||||
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,f=Math.cos(b),j=Math.sin(b),m=1-f,n=a.x,k=a.y,o=a.z;d.n11=m*n*n+f;d.n12=m*n*k-j*o;d.n13=m*n*o+j*k;d.n21=m*n*k+j*o;d.n22=m*k*k+f;d.n23=m*k*o-j*n;d.n31=m*n*o-j*k;d.n32=m*k*o+j*n;d.n33=m*o*o+f;return d};
|
||||
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 d=b[10]*b[5]-b[6]*b[9],g=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],n=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],k=-b[6]*b[0]+b[2]*b[4],o=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],F=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*n+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*g;a.m[2]=b*j;a.m[3]=b*n;a.m[4]=b*m;a.m[5]=b*k;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*F;return a};
|
||||
THREE.Matrix4.makeFrustum=function(a,b,d,g,j,n){var m,k,o;m=new THREE.Matrix4;k=2*j/(b-a);o=2*j/(g-d);a=(b+a)/(b-a);d=(g+d)/(g-d);g=-(n+j)/(n-j);j=-2*n*j/(n-j);m.n11=k;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=o;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=g;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,g){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,g)};
|
||||
THREE.Matrix4.makeOrtho=function(a,b,d,g,j,n){var m,k,o,c;m=new THREE.Matrix4;k=b-a;o=d-g;c=n-j;a=(b+a)/k;d=(d+g)/o;j=(n+j)/c;m.n11=2/k;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/o;m.n23=0;m.n24=-d;m.n31=0;m.n32=0;m.n33=-2/c;m.n34=-j;m.n41=0;m.n42=0;m.n43=0;m.n44=1;return m};
|
||||
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.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
|
||||
THREE.Face3=function(a,b,d,g,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
|
||||
THREE.Face4=function(a,b,d,g,j,n){this.a=a;this.b=b;this.c=d;this.d=g;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=n instanceof Array?n:[n]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
|
||||
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
|
||||
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],f=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],m=-b[10]*b[4]+b[6]*b[8],n=b[10]*b[0]-b[2]*b[8],k=-b[6]*b[0]+b[2]*b[4],o=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],E=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*m+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*f;a.m[2]=b*j;a.m[3]=b*m;a.m[4]=b*n;a.m[5]=b*k;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*E;return a};
|
||||
THREE.Matrix4.makeFrustum=function(a,b,d,f,j,m){var n,k,o;n=new THREE.Matrix4;k=2*j/(b-a);o=2*j/(f-d);a=(b+a)/(b-a);d=(f+d)/(f-d);f=-(m+j)/(m-j);j=-2*m*j/(m-j);n.n11=k;n.n12=0;n.n13=a;n.n14=0;n.n21=0;n.n22=o;n.n23=d;n.n24=0;n.n31=0;n.n32=0;n.n33=f;n.n34=j;n.n41=0;n.n42=0;n.n43=-1;n.n44=0;return n};THREE.Matrix4.makePerspective=function(a,b,d,f){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,f)};
|
||||
THREE.Matrix4.makeOrtho=function(a,b,d,f,j,m){var n,k,o,c;n=new THREE.Matrix4;k=b-a;o=d-f;c=m-j;a=(b+a)/k;d=(d+f)/o;j=(m+j)/c;n.n11=2/k;n.n12=0;n.n13=0;n.n14=-a;n.n21=0;n.n22=2/o;n.n23=0;n.n24=-d;n.n31=0;n.n32=0;n.n33=-2/c;n.n34=-j;n.n41=0;n.n42=0;n.n43=0;n.n44=1;return n};
|
||||
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
|
||||
THREE.Face3=function(a,b,d,f,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
|
||||
THREE.Face4=function(a,b,d,f,j,m){this.a=a;this.b=b;this.c=d;this.d=f;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=m instanceof Array?m:[m]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
|
||||
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={};this.hasTangents=false};
|
||||
THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
|
||||
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,g,j,n,m,k=new THREE.Vector3,o=new THREE.Vector3;g=0;for(j=this.vertices.length;g<j;g++){n=this.vertices[g];n.normal.set(0,0,0)}g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];if(a&&n.vertexNormals.length){k.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)k.addSelf(n.vertexNormals[b]);k.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];m=this.vertices[n.c];k.sub(m.position,
|
||||
d.position);o.sub(b.position,d.position);k.crossSelf(o)}k.isZero()||k.normalize();n.normal.copy(k)}},computeVertexNormals:function(){var a,b=[],d,g;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal)}else if(g instanceof THREE.Face4){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal);b[g.d].addSelf(g.normal)}}a=
|
||||
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone()}else if(g instanceof THREE.Face4){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone();g.vertexNormals[3]=b[g.d].clone()}}},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;
|
||||
if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(F){var D=[];b=0;for(d=F.length;b<d;b++)F[b]==undefined?D.push("undefined"):D.push(F[b].toString());return D.join("_")}var b,d,g,j,n,m,k,o,c={};g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];m=n.material;k=a(m);if(c[k]==undefined)c[k]={hash:k,counter:0};o=c[k].hash+"_"+c[k].counter;if(this.geometryChunks[o]==
|
||||
undefined)this.geometryChunks[o]={faces:[],material:m,vertices:0};n=n instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+n>65535){c[k].counter+=1;o=c[k].hash+"_"+c[k].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:m,vertices:0}}this.geometryChunks[o].faces.push(g);this.geometryChunks[o].vertices+=n}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
|
||||
THREE.Camera=function(a,b,d,g){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,g);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
|
||||
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,f,j,m,n,k=new THREE.Vector3,o=new THREE.Vector3;f=0;for(j=this.vertices.length;f<j;f++){m=this.vertices[f];m.normal.set(0,0,0)}f=0;for(j=this.faces.length;f<j;f++){m=this.faces[f];if(a&&m.vertexNormals.length){k.set(0,0,0);b=0;for(d=m.normal.length;b<d;b++)k.addSelf(m.vertexNormals[b]);k.divideScalar(3)}else{b=this.vertices[m.a];d=this.vertices[m.b];n=this.vertices[m.c];k.sub(n.position,
|
||||
d.position);o.sub(b.position,d.position);k.crossSelf(o)}k.isZero()||k.normalize();m.normal.copy(k)}},computeVertexNormals:function(){var a,b=[],d,f;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){f=this.faces[a];if(f instanceof THREE.Face3){b[f.a].addSelf(f.normal);b[f.b].addSelf(f.normal);b[f.c].addSelf(f.normal)}else if(f instanceof THREE.Face4){b[f.a].addSelf(f.normal);b[f.b].addSelf(f.normal);b[f.c].addSelf(f.normal);b[f.d].addSelf(f.normal)}}a=
|
||||
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){f=this.faces[a];if(f instanceof THREE.Face3){f.vertexNormals[0]=b[f.a].clone();f.vertexNormals[1]=b[f.b].clone();f.vertexNormals[2]=b[f.c].clone()}else if(f instanceof THREE.Face4){f.vertexNormals[0]=b[f.a].clone();f.vertexNormals[1]=b[f.b].clone();f.vertexNormals[2]=b[f.c].clone();f.vertexNormals[3]=b[f.d].clone()}}},computeTangents:function(){function a(w,I,S,t){m=w.vertices[I].position;n=w.vertices[S].position;
|
||||
k=w.vertices[t].position;o=j[0];c=j[1];E=j[2];C=n.x-m.x;x=k.x-m.x;z=n.y-m.y;H=k.y-m.y;G=n.z-m.z;J=k.z-m.z;L=c.u-o.u;M=E.u-o.u;u=c.v-o.v;e=E.v-o.v;l=1/(L*e-M*u);i.set((e*C-u*x)*l,(e*z-u*H)*l,(e*G-u*J)*l);s.set((L*x-M*C)*l,(L*H-M*z)*l,(L*J-M*G)*l);q[I].addSelf(i);q[S].addSelf(i);q[t].addSelf(i);h[I].addSelf(s);h[S].addSelf(s);h[t].addSelf(s)}var b,d,f,j,m,n,k,o,c,E,C,x,z,H,G,J,L,M,u,e,l,g,q=[],h=[],i=new THREE.Vector3,s=new THREE.Vector3,p=new THREE.Vector3,D=new THREE.Vector3;g=new THREE.Vector3;b=
|
||||
0;for(d=this.vertices.length;b<d;b++){q[b]=new THREE.Vector3;h[b]=new THREE.Vector3}b=0;for(d=this.faces.length;b<d;b++){f=this.faces[b];j=this.uvs[b];if(f instanceof THREE.Face3){a(this,f.a,f.b,f.c);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2])}else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.c);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);
|
||||
this.vertices[f.c].normal.copy(f.vertexNormals[2]);this.vertices[f.d].normal.copy(f.vertexNormals[3])}}b=0;for(d=this.vertices.length;b<d;b++){g.copy(this.vertices[b].normal);f=q[b];p.copy(f);p.subSelf(g.multiplyScalar(g.dot(f))).normalize();D.cross(this.vertices[b].normal,f);test=D.dot(h[b]);f=test<0?-1:1;this.vertices[b].tangent.set(p.x,p.y,p.z,f)}this.hasTangents=true},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=
|
||||
vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(E){var C=[];b=0;for(d=E.length;b<d;b++)E[b]==undefined?C.push("undefined"):C.push(E[b].toString());return C.join("_")}var b,d,f,j,m,n,k,o,c={};f=0;for(j=this.faces.length;f<j;f++){m=this.faces[f];n=m.material;k=a(n);if(c[k]==undefined)c[k]={hash:k,counter:0};o=c[k].hash+"_"+c[k].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:n,
|
||||
vertices:0};m=m instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+m>65535){c[k].counter+=1;o=c[k].hash+"_"+c[k].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:n,vertices:0}}this.geometryChunks[o].faces.push(f);this.geometryChunks[o].vertices+=m}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
|
||||
THREE.Camera=function(a,b,d,f){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,f);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
|
||||
THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
|
||||
THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
|
||||
THREE.Object3D=function(){this.id=THREE.Object3DCounter.value++;this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.matrix=new THREE.Matrix4;this.translationMatrix=new THREE.Matrix4;this.rotationMatrix=new THREE.Matrix4;this.scaleMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.autoUpdateMatrix=this.visible=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);
|
||||
this.rotationMatrix=THREE.Matrix4.rotationXMatrix(this.rotation.x);this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.scaleMatrix=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);this.matrix.multiplySelf(this.rotationMatrix);this.matrix.multiplySelf(this.scaleMatrix)}};THREE.Object3DCounter={value:0};
|
||||
THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.Line=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
|
||||
THREE.Mesh=function(a,b,d){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;d&&this.normalizeUVs();this.geometry.computeBoundingBox()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;
|
||||
THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,g,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(g=j.length;d<g;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
|
||||
THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,f,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(f=j.length;d<f;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
|
||||
THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;this.linewidth=1;this.linejoin=this.linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.linewidth!==undefined)this.linewidth=a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+
|
||||
this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
|
||||
THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(15658734);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=
|
||||
@@ -82,92 +85,94 @@ undefined)this.uniforms=a.uniforms;if(a.shading!==undefined)this.shading=a.shadi
|
||||
THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.offset=new THREE.Vector2;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+
|
||||
this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
|
||||
THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
|
||||
THREE.Texture=function(a,b,d,g,j,n){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=g!==undefined?g:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=n!==undefined?n:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
|
||||
THREE.Texture=function(a,b,d,f,j,m){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=f!==undefined?f:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=m!==undefined?m:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
|
||||
this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
|
||||
THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
|
||||
THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
|
||||
THREE.Projector=function(){function a(O,v){var f=0,l=1,e=O.z+O.w,q=v.z+v.w,h=-O.z+O.w,i=-v.z+v.w;if(e>=0&&q>=0&&h>=0&&i>=0)return true;else if(e<0&&q<0||h<0&&i<0)return false;else{if(e<0)f=Math.max(f,e/(e-q));else if(q<0)l=Math.min(l,e/(e-q));if(h<0)f=Math.max(f,h/(h-i));else if(i<0)l=Math.min(l,h/(h-i));if(l<f)return false;else{O.lerpSelf(v,f);v.lerpSelf(O,1-l);return true}}}var b=null,d,g,j,n=[],m,k,o=[],c,F,D=[],w=new THREE.Vector4,x=new THREE.Matrix4,I=new THREE.Matrix4,G=new THREE.Vector4,L=
|
||||
new THREE.Vector4,N;this.projectScene=function(O,v){var f,l,e,q,h,i,s,r,M,B,H,Q,u,R,y,A,E;b=[];j=k=F=0;v.autoUpdateMatrix&&v.updateMatrix();x.multiply(v.projectionMatrix,v.matrix);s=O.objects;f=0;for(l=s.length;f<l;f++){r=s[f];r.autoUpdateMatrix&&r.updateMatrix();M=r.matrix;B=r.rotationMatrix;H=r.material;Q=r.overdraw;if(r instanceof THREE.Mesh){u=r.geometry.vertices;e=0;for(q=u.length;e<q;e++){R=u[e];R.positionWorld.copy(R.position);M.multiplyVector3(R.positionWorld);y=R.positionScreen;y.copy(R.positionWorld);
|
||||
x.multiplyVector4(y);y.multiplyScalar(1/y.w);R.__visible=y.z>0&&y.z<1}R=r.geometry.faces;e=0;for(q=R.length;e<q;e++){y=R[e];if(y instanceof THREE.Face3){h=u[y.a];i=u[y.b];A=u[y.c];if(h.__visible&&i.__visible&&A.__visible)if(r.doubleSided||r.flipSided!=(A.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(A.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<0){d=n[j]=n[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);
|
||||
d.v3.positionWorld.copy(A.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(A.positionScreen);d.normalWorld.copy(y.normal);B.multiplyVector3(d.normalWorld);d.centroidWorld.copy(y.centroid);M.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);x.multiplyVector3(d.centroidScreen);A=y.vertexNormals;N=d.vertexNormalsWorld;h=0;for(i=A.length;h<i;h++){E=N[h]=N[h]||new THREE.Vector3;E.copy(A[h]);B.multiplyVector3(E)}d.z=
|
||||
d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=y.material;d.overdraw=Q;if(r.geometry.uvs[e]){d.uvs[0]=r.geometry.uvs[e][0];d.uvs[1]=r.geometry.uvs[e][1];d.uvs[2]=r.geometry.uvs[e][2]}b.push(d);j++}}else if(y instanceof THREE.Face4){h=u[y.a];i=u[y.b];A=u[y.c];E=u[y.d];if(h.__visible&&i.__visible&&A.__visible&&E.__visible)if(r.doubleSided||r.flipSided!=((E.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(E.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<
|
||||
0||(i.positionScreen.x-A.positionScreen.x)*(E.positionScreen.y-A.positionScreen.y)-(i.positionScreen.y-A.positionScreen.y)*(E.positionScreen.x-A.positionScreen.x)<0)){d=n[j]=n[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);d.v3.positionWorld.copy(E.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(E.positionScreen);d.normalWorld.copy(y.normal);B.multiplyVector3(d.normalWorld);
|
||||
d.centroidWorld.copy(y.centroid);M.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);x.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=y.material;d.overdraw=Q;if(r.geometry.uvs[e]){d.uvs[0]=r.geometry.uvs[e][0];d.uvs[1]=r.geometry.uvs[e][1];d.uvs[2]=r.geometry.uvs[e][3]}b.push(d);j++;g=n[j]=n[j]||new THREE.RenderableFace3;g.v1.positionWorld.copy(i.positionWorld);g.v2.positionWorld.copy(A.positionWorld);g.v3.positionWorld.copy(E.positionWorld);
|
||||
g.v1.positionScreen.copy(i.positionScreen);g.v2.positionScreen.copy(A.positionScreen);g.v3.positionScreen.copy(E.positionScreen);g.normalWorld.copy(d.normalWorld);g.centroidWorld.copy(d.centroidWorld);g.centroidScreen.copy(d.centroidScreen);g.z=g.centroidScreen.z;g.meshMaterial=H;g.faceMaterial=y.material;g.overdraw=Q;if(r.geometry.uvs[e]){g.uvs[0]=r.geometry.uvs[e][1];g.uvs[1]=r.geometry.uvs[e][2];g.uvs[2]=r.geometry.uvs[e][3]}b.push(g);j++}}}}else if(r instanceof THREE.Line){I.multiply(x,M);u=r.geometry.vertices;
|
||||
R=u[0];R.positionScreen.copy(R.position);I.multiplyVector4(R.positionScreen);e=1;for(q=u.length;e<q;e++){h=u[e];h.positionScreen.copy(h.position);I.multiplyVector4(h.positionScreen);i=u[e-1];G.copy(h.positionScreen);L.copy(i.positionScreen);if(a(G,L)){G.multiplyScalar(1/G.w);L.multiplyScalar(1/L.w);m=o[k]=o[k]||new THREE.RenderableLine;m.v1.positionScreen.copy(G);m.v2.positionScreen.copy(L);m.z=Math.max(G.z,L.z);m.material=r.material;b.push(m);k++}}}else if(r instanceof THREE.Particle){w.set(r.position.x,
|
||||
r.position.y,r.position.z,1);x.multiplyVector4(w);w.z/=w.w;if(w.z>0&&w.z<1){c=D[F]=D[F]||new THREE.RenderableParticle;c.x=w.x/w.w;c.y=w.y/w.w;c.z=w.z;c.rotation=r.rotation.z;c.scale.x=r.scale.x*Math.abs(c.x-(w.x+v.projectionMatrix.n11)/(w.w+v.projectionMatrix.n14));c.scale.y=r.scale.y*Math.abs(c.y-(w.y+v.projectionMatrix.n22)/(w.w+v.projectionMatrix.n24));c.material=r.material;b.push(c);F++}}}b.sort(function(W,J){return J.z-W.z});return b};this.unprojectVector=function(O,v){var f=new THREE.Matrix4;
|
||||
f.multiply(THREE.Matrix4.makeInvert(v.matrix),THREE.Matrix4.makeInvert(v.projectionMatrix));f.multiplyVector3(O);return O}};
|
||||
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,g,j,n;this.domElement=document.createElement("div");this.setSize=function(m,k){d=m;g=k;j=d/2;n=g/2};this.render=function(m,k){var o,c,F,D,w,x,I,G;a=b.projectScene(m,k);o=0;for(c=a.length;o<c;o++){w=a[o];if(w instanceof THREE.RenderableParticle){I=w.x*j+j;G=w.y*n+n;F=0;for(D=w.material.length;F<D;F++){x=w.material[F];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=I+"px";x.style.top=G+"px"}}}}}};
|
||||
THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),g,j,n,m,k=d.getContext("2d"),o=1,c=0,F=null,D=null,w=1,x=Math.min,I=Math.max,G,L,N,O,v,f,l,e,q,h=new THREE.Color,i=new THREE.Color,s=new THREE.Color,r=new THREE.Color,M=new THREE.Color,B,H,Q,u,R,y,A,E,W,J,z=new THREE.Rectangle,S=new THREE.Rectangle,X=new THREE.Rectangle,T=false,P=new THREE.Color,Z=new THREE.Color,ia=new THREE.Color,ja=new THREE.Color,La=Math.PI*2,Y=new THREE.Vector3,na,oa,Ca,ba,pa,
|
||||
va,la=16;na=document.createElement("canvas");na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Ca=oa.getImageData(0,0,2,2);ba=Ca.data;pa=document.createElement("canvas");pa.width=pa.height=la;va=pa.getContext("2d");va.translate(-la/2,-la/2);va.scale(la,la);la--;this.domElement=d;this.autoClear=true;this.setSize=function(fa,wa){g=fa;j=wa;n=g/2;m=j/2;d.width=g;d.height=j;z.set(-n,-m,n,m)};this.clear=function(){if(!S.isEmpty()){S.inflate(1);S.minSelf(z);k.clearRect(S.getX(),
|
||||
S.getY(),S.getWidth(),S.getHeight());S.empty()}};this.render=function(fa,wa){function Ma(p){var U,K,t,C=p.lights;Z.setRGB(0,0,0);ia.setRGB(0,0,0);ja.setRGB(0,0,0);p=0;for(U=C.length;p<U;p++){K=C[p];t=K.color;if(K instanceof THREE.AmbientLight){Z.r+=t.r;Z.g+=t.g;Z.b+=t.b}else if(K instanceof THREE.DirectionalLight){ia.r+=t.r;ia.g+=t.g;ia.b+=t.b}else if(K instanceof THREE.PointLight){ja.r+=t.r;ja.g+=t.g;ja.b+=t.b}}}function xa(p,U,K,t){var C,V,aa,ca,da=p.lights;p=0;for(C=da.length;p<C;p++){V=da[p];
|
||||
aa=V.color;ca=V.intensity;if(V instanceof THREE.DirectionalLight){V=K.dot(V.position)*ca;if(V>0){t.r+=aa.r*V;t.g+=aa.g*V;t.b+=aa.b*V}}else if(V instanceof THREE.PointLight){Y.sub(V.position,U);Y.normalize();V=K.dot(Y)*ca;if(V>0){t.r+=aa.r*V;t.g+=aa.g*V;t.b+=aa.b*V}}}}function Na(p,U,K){if(K.opacity!=0){Da(K.opacity);ya(K.blending);var t,C,V,aa,ca,da;if(K instanceof THREE.ParticleBasicMaterial){if(K.map){aa=K.map;ca=aa.width>>1;da=aa.height>>1;C=U.scale.x*n;V=U.scale.y*m;K=C*ca;t=V*da;X.set(p.x-K,
|
||||
p.y-t,p.x+K,p.y+t);if(!z.instersects(X))return;k.save();k.translate(p.x,p.y);k.rotate(-U.rotation);k.scale(C,-V);k.translate(-ca,-da);k.drawImage(aa,0,0);k.restore()}k.beginPath();k.moveTo(p.x-10,p.y);k.lineTo(p.x+10,p.y);k.moveTo(p.x,p.y-10);k.lineTo(p.x,p.y+10);k.closePath();k.strokeStyle="rgb(255,255,0)";k.stroke()}else if(K instanceof THREE.ParticleCircleMaterial){if(T){P.r=Z.r+ia.r+ja.r;P.g=Z.g+ia.g+ja.g;P.b=Z.b+ia.b+ja.b;h.r=K.color.r*P.r;h.g=K.color.g*P.g;h.b=K.color.b*P.b;h.updateStyleString()}else h.__styleString=
|
||||
K.color.__styleString;K=U.scale.x*n;t=U.scale.y*m;X.set(p.x-K,p.y-t,p.x+K,p.y+t);if(z.instersects(X)){C=h.__styleString;if(D!=C)k.fillStyle=D=C;k.save();k.translate(p.x,p.y);k.rotate(-U.rotation);k.scale(K,t);k.beginPath();k.arc(0,0,1,0,La,true);k.closePath();k.fill();k.restore()}}}}function Oa(p,U,K,t){if(t.opacity!=0){Da(t.opacity);ya(t.blending);k.beginPath();k.moveTo(p.positionScreen.x,p.positionScreen.y);k.lineTo(U.positionScreen.x,U.positionScreen.y);k.closePath();if(t instanceof THREE.LineBasicMaterial){h.__styleString=
|
||||
t.color.__styleString;p=t.linewidth;if(w!=p)k.lineWidth=w=p;p=h.__styleString;if(F!=p)k.strokeStyle=F=p;k.stroke();X.inflate(t.linewidth*2)}}}function Ha(p,U,K,t,C,V){if(C.opacity!=0){Da(C.opacity);ya(C.blending);O=p.positionScreen.x;v=p.positionScreen.y;f=U.positionScreen.x;l=U.positionScreen.y;e=K.positionScreen.x;q=K.positionScreen.y;k.beginPath();k.moveTo(O,v);k.lineTo(f,l);k.lineTo(e,q);k.lineTo(O,v);k.closePath();if(C instanceof THREE.MeshBasicMaterial)if(C.map)C.map.image.loaded&&C.map.mapping instanceof
|
||||
THREE.UVMapping&&qa(O,v,f,l,e,q,C.map.image,t.uvs[0].u,t.uvs[0].v,t.uvs[1].u,t.uvs[1].v,t.uvs[2].u,t.uvs[2].v);else if(C.env_map){if(C.env_map.image.loaded)if(C.env_map.mapping instanceof THREE.SphericalReflectionMapping){p=wa.matrix;Y.copy(t.vertexNormalsWorld[0]);R=(Y.x*p.n11+Y.y*p.n12+Y.z*p.n13)*0.5+0.5;y=-(Y.x*p.n21+Y.y*p.n22+Y.z*p.n23)*0.5+0.5;Y.copy(t.vertexNormalsWorld[1]);A=(Y.x*p.n11+Y.y*p.n12+Y.z*p.n13)*0.5+0.5;E=-(Y.x*p.n21+Y.y*p.n22+Y.z*p.n23)*0.5+0.5;Y.copy(t.vertexNormalsWorld[2]);W=
|
||||
(Y.x*p.n11+Y.y*p.n12+Y.z*p.n13)*0.5+0.5;J=-(Y.x*p.n21+Y.y*p.n22+Y.z*p.n23)*0.5+0.5;qa(O,v,f,l,e,q,C.env_map.image,R,y,A,E,W,J)}}else C.wireframe?za(C.color.__styleString,C.wireframe_linewidth):Aa(C.color.__styleString);else if(C instanceof THREE.MeshLambertMaterial){if(C.map&&!C.wireframe){C.map.mapping instanceof THREE.UVMapping&&qa(O,v,f,l,e,q,C.map.image,t.uvs[0].u,t.uvs[0].v,t.uvs[1].u,t.uvs[1].v,t.uvs[2].u,t.uvs[2].v);ya(THREE.SubtractiveBlending)}if(T)if(!C.wireframe&&C.shading==THREE.SmoothShading&&
|
||||
t.vertexNormalsWorld.length==3){i.r=s.r=r.r=Z.r;i.g=s.g=r.g=Z.g;i.b=s.b=r.b=Z.b;xa(V,t.v1.positionWorld,t.vertexNormalsWorld[0],i);xa(V,t.v2.positionWorld,t.vertexNormalsWorld[1],s);xa(V,t.v3.positionWorld,t.vertexNormalsWorld[2],r);M.r=(s.r+r.r)*0.5;M.g=(s.g+r.g)*0.5;M.b=(s.b+r.b)*0.5;u=Ia(i,s,r,M);qa(O,v,f,l,e,q,u,0,0,1,0,0,1)}else{P.r=Z.r;P.g=Z.g;P.b=Z.b;xa(V,t.centroidWorld,t.normalWorld,P);h.r=C.color.r*P.r;h.g=C.color.g*P.g;h.b=C.color.b*P.b;h.updateStyleString();C.wireframe?za(h.__styleString,
|
||||
C.wireframe_linewidth):Aa(h.__styleString)}else C.wireframe?za(C.color.__styleString,C.wireframe_linewidth):Aa(C.color.__styleString)}else if(C instanceof THREE.MeshDepthMaterial){B=C.__2near;H=C.__farPlusNear;Q=C.__farMinusNear;i.r=i.g=i.b=1-B/(H-p.positionScreen.z*Q);s.r=s.g=s.b=1-B/(H-U.positionScreen.z*Q);r.r=r.g=r.b=1-B/(H-K.positionScreen.z*Q);M.r=(s.r+r.r)*0.5;M.g=(s.g+r.g)*0.5;M.b=(s.b+r.b)*0.5;u=Ia(i,s,r,M);qa(O,v,f,l,e,q,u,0,0,1,0,0,1)}else if(C instanceof THREE.MeshNormalMaterial){h.r=
|
||||
Ea(t.normalWorld.x);h.g=Ea(t.normalWorld.y);h.b=Ea(t.normalWorld.z);h.updateStyleString();C.wireframe?za(h.__styleString,C.wireframe_linewidth):Aa(h.__styleString)}}}function za(p,U){if(F!=p)k.strokeStyle=F=p;if(w!=U)k.lineWidth=w=U;k.stroke();X.inflate(U*2)}function Aa(p){if(D!=p)k.fillStyle=D=p;k.fill()}function qa(p,U,K,t,C,V,aa,ca,da,ra,ha,sa,ta){var ka,ga;ka=aa.width-1;ga=aa.height-1;ca*=ka;da*=ga;ra*=ka;ha*=ga;sa*=ka;ta*=ga;K-=p;t-=U;C-=p;V-=U;ra-=ca;ha-=da;sa-=ca;ta-=da;ga=1/(ra*ta-sa*ha);
|
||||
ka=(ta*K-ha*C)*ga;ha=(ta*t-ha*V)*ga;K=(ra*C-sa*K)*ga;t=(ra*V-sa*t)*ga;p=p-ka*ca-K*da;U=U-ha*ca-t*da;k.save();k.transform(ka,ha,K,t,p,U);k.clip();k.drawImage(aa,0,0);k.restore()}function Da(p){if(o!=p)k.globalAlpha=o=p}function ya(p){if(c!=p){switch(p){case THREE.NormalBlending:k.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:k.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:k.globalCompositeOperation="darker"}c=p}}function Ia(p,U,K,t){ba[0]=I(0,x(255,
|
||||
~~(p.r*255)));ba[1]=I(0,x(255,~~(p.g*255)));ba[2]=I(0,x(255,~~(p.b*255)));ba[4]=I(0,x(255,~~(U.r*255)));ba[5]=I(0,x(255,~~(U.g*255)));ba[6]=I(0,x(255,~~(U.b*255)));ba[8]=I(0,x(255,~~(K.r*255)));ba[9]=I(0,x(255,~~(K.g*255)));ba[10]=I(0,x(255,~~(K.b*255)));ba[12]=I(0,x(255,~~(t.r*255)));ba[13]=I(0,x(255,~~(t.g*255)));ba[14]=I(0,x(255,~~(t.b*255)));oa.putImageData(Ca,0,0);va.drawImage(na,0,0);return pa}function Ea(p){return p<0?x((1+p)*0.5,0.5):0.5+x(p*0.5,0.5)}function Fa(p,U){var K=U.x-p.x,t=U.y-p.y,
|
||||
C=1/Math.sqrt(K*K+t*t);K*=C;t*=C;U.x+=K;U.y+=t;p.x-=K;p.y-=t}var Ba,Ja,$,ea,ma,Ga,Ka,ua;k.setTransform(1,0,0,-1,n,m);this.autoClear&&this.clear();a=b.projectScene(fa,wa);k.fillStyle="rgba(0, 255, 255, 0.5)";k.fillRect(z.getX(),z.getY(),z.getWidth(),z.getHeight());(T=fa.lights.length>0)&&Ma(fa);Ba=0;for(Ja=a.length;Ba<Ja;Ba++){$=a[Ba];X.empty();if($ instanceof THREE.RenderableParticle){G=$;G.x*=n;G.y*=m;ea=0;for(ma=$.material.length;ea<ma;ea++)Na(G,$,$.material[ea],fa)}else if($ instanceof THREE.RenderableLine){G=
|
||||
$.v1;L=$.v2;G.positionScreen.x*=n;G.positionScreen.y*=m;L.positionScreen.x*=n;L.positionScreen.y*=m;X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);if(z.instersects(X)){ea=0;for(ma=$.material.length;ea<ma;)Oa(G,L,$,$.material[ea++],fa)}}else if($ instanceof THREE.RenderableFace3){G=$.v1;L=$.v2;N=$.v3;G.positionScreen.x*=n;G.positionScreen.y*=m;L.positionScreen.x*=n;L.positionScreen.y*=m;N.positionScreen.x*=n;N.positionScreen.y*=m;if($.overdraw){Fa(G.positionScreen,
|
||||
L.positionScreen);Fa(L.positionScreen,N.positionScreen);Fa(N.positionScreen,G.positionScreen)}X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);X.addPoint(N.positionScreen.x,N.positionScreen.y);if(z.instersects(X)){ea=0;for(ma=$.meshMaterial.length;ea<ma;){ua=$.meshMaterial[ea++];if(ua instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterial.length;Ga<Ka;)(ua=$.faceMaterial[Ga++])&&Ha(G,L,N,$,ua,fa)}else Ha(G,L,N,$,ua,fa)}}}S.addRectangle(X)}k.lineWidth=
|
||||
1;k.strokeStyle="rgba( 255, 0, 0, 0.5 )";k.strokeRect(S.getX(),S.getY(),S.getWidth(),S.getHeight());k.setTransform(1,0,0,1,0,0)}};
|
||||
THREE.SVGRenderer=function(){function a(y,A,E){var W,J,z,S;W=0;for(J=y.lights.length;W<J;W++){z=y.lights[W];if(z instanceof THREE.DirectionalLight){S=A.normalWorld.dot(z.position)*z.intensity;if(S>0){E.r+=z.color.r*S;E.g+=z.color.g*S;E.b+=z.color.b*S}}else if(z instanceof THREE.PointLight){i.sub(z.position,A.centroidWorld);i.normalize();S=A.normalWorld.dot(i)*z.intensity;if(S>0){E.r+=z.color.r*S;E.g+=z.color.g*S;E.b+=z.color.b*S}}}}function b(y,A,E,W,J,z){B=g(H++);B.setAttribute("d","M "+y.positionScreen.x+
|
||||
" "+y.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+E.positionScreen.x+","+E.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)v.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(O){f.r=l.r;f.g=l.g;f.b=l.b;a(z,W,f);v.r=J.color.r*f.r;v.g=J.color.g*f.g;v.b=J.color.b*f.b;v.updateStyleString()}else v.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){h=1-J.__2near/(J.__farPlusNear-W.z*J.__farMinusNear);
|
||||
v.setRGB(h,h,h)}else J instanceof THREE.MeshNormalMaterial&&v.setRGB(j(W.normalWorld.x),j(W.normalWorld.y),j(W.normalWorld.z));J.wireframe?B.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):B.setAttribute("style","fill: "+v.__styleString+"; fill-opacity: "+J.opacity);k.appendChild(B)}function d(y,A,E,W,J,z,S){B=g(H++);B.setAttribute("d",
|
||||
"M "+y.positionScreen.x+" "+y.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+E.positionScreen.x+","+E.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+"z");if(z instanceof THREE.MeshBasicMaterial)v.__styleString=z.color.__styleString;else if(z instanceof THREE.MeshLambertMaterial)if(O){f.r=l.r;f.g=l.g;f.b=l.b;a(S,J,f);v.r=z.color.r*f.r;v.g=z.color.g*f.g;v.b=z.color.b*f.b;v.updateStyleString()}else v.__styleString=z.color.__styleString;else if(z instanceof THREE.MeshDepthMaterial){h=
|
||||
1-z.__2near/(z.__farPlusNear-J.z*z.__farMinusNear);v.setRGB(h,h,h)}else z instanceof THREE.MeshNormalMaterial&&v.setRGB(j(J.normalWorld.x),j(J.normalWorld.y),j(J.normalWorld.z));z.wireframe?B.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+z.wireframe_linewidth+"; stroke-opacity: "+z.opacity+"; stroke-linecap: "+z.wireframe_linecap+"; stroke-linejoin: "+z.wireframe_linejoin):B.setAttribute("style","fill: "+v.__styleString+"; fill-opacity: "+z.opacity);k.appendChild(B)}
|
||||
function g(y){if(s[y]==null){s[y]=document.createElementNS("http://www.w3.org/2000/svg","path");R==0&&s[y].setAttribute("shape-rendering","crispEdges");return s[y]}return s[y]}function j(y){return y<0?Math.min((1+y)*0.5,0.5):0.5+Math.min(y*0.5,0.5)}var n=null,m=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,F,D,w,x,I,G,L=new THREE.Rectangle,N=new THREE.Rectangle,O=false,v=new THREE.Color(16777215),f=new THREE.Color(16777215),l=new THREE.Color(0),e=new THREE.Color(0),
|
||||
q=new THREE.Color(0),h,i=new THREE.Vector3,s=[],r=[],M=[],B,H,Q,u,R=1;this.domElement=k;this.autoClear=true;this.setQuality=function(y){switch(y){case "high":R=1;break;case "low":R=0}};this.setSize=function(y,A){o=y;c=A;F=o/2;D=c/2;k.setAttribute("viewBox",-F+" "+-D+" "+o+" "+c);k.setAttribute("width",o);k.setAttribute("height",c);L.set(-F,-D,F,D)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};this.render=function(y,A){var E,W,J,z,S,X,T,P;this.autoClear&&this.clear();
|
||||
n=m.projectScene(y,A);u=Q=H=0;if(O=y.lights.length>0){T=y.lights;l.setRGB(0,0,0);e.setRGB(0,0,0);q.setRGB(0,0,0);E=0;for(W=T.length;E<W;E++){J=T[E];z=J.color;if(J instanceof THREE.AmbientLight){l.r+=z.r;l.g+=z.g;l.b+=z.b}else if(J instanceof THREE.DirectionalLight){e.r+=z.r;e.g+=z.g;e.b+=z.b}else if(J instanceof THREE.PointLight){q.r+=z.r;q.g+=z.g;q.b+=z.b}}}E=0;for(W=n.length;E<W;E++){T=n[E];N.empty();if(T instanceof THREE.RenderableParticle){w=T;w.x*=F;w.y*=-D;J=0;for(z=T.material.length;J<z;J++)if(P=
|
||||
T.material[J]){S=w;X=T;P=P;var Z=Q++;if(r[Z]==null){r[Z]=document.createElementNS("http://www.w3.org/2000/svg","circle");R==0&&r[Z].setAttribute("shape-rendering","crispEdges")}B=r[Z];B.setAttribute("cx",S.x);B.setAttribute("cy",S.y);B.setAttribute("r",X.scale.x*F);if(P instanceof THREE.ParticleCircleMaterial){if(O){f.r=l.r+e.r+q.r;f.g=l.g+e.g+q.g;f.b=l.b+e.b+q.b;v.r=P.color.r*f.r;v.g=P.color.g*f.g;v.b=P.color.b*f.b;v.updateStyleString()}else v=P.color;B.setAttribute("style","fill: "+v.__styleString)}k.appendChild(B)}}else if(T instanceof
|
||||
THREE.RenderableLine){w=T.v1;x=T.v2;w.positionScreen.x*=F;w.positionScreen.y*=-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);if(L.instersects(N)){J=0;for(z=T.material.length;J<z;)if(P=T.material[J++]){S=w;X=x;P=P;Z=u++;if(M[Z]==null){M[Z]=document.createElementNS("http://www.w3.org/2000/svg","line");R==0&&M[Z].setAttribute("shape-rendering","crispEdges")}B=M[Z];B.setAttribute("x1",S.positionScreen.x);
|
||||
B.setAttribute("y1",S.positionScreen.y);B.setAttribute("x2",X.positionScreen.x);B.setAttribute("y2",X.positionScreen.y);if(P instanceof THREE.LineBasicMaterial){v.__styleString=P.color.__styleString;B.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+P.linewidth+"; stroke-opacity: "+P.opacity+"; stroke-linecap: "+P.linecap+"; stroke-linejoin: "+P.linejoin);k.appendChild(B)}}}}else if(T instanceof THREE.RenderableFace3){w=T.v1;x=T.v2;I=T.v3;w.positionScreen.x*=F;w.positionScreen.y*=
|
||||
-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;I.positionScreen.x*=F;I.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);N.addPoint(I.positionScreen.x,I.positionScreen.y);if(L.instersects(N)){J=0;for(z=T.meshMaterial.length;J<z;){P=T.meshMaterial[J++];if(P instanceof THREE.MeshFaceMaterial){S=0;for(X=T.faceMaterial.length;S<X;)(P=T.faceMaterial[S++])&&b(w,x,I,T,P,y)}else P&&b(w,x,I,T,P,y)}}}else if(T instanceof THREE.RenderableFace4){w=
|
||||
T.v1;x=T.v2;I=T.v3;G=T.v4;w.positionScreen.x*=F;w.positionScreen.y*=-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;I.positionScreen.x*=F;I.positionScreen.y*=-D;G.positionScreen.x*=F;G.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);N.addPoint(I.positionScreen.x,I.positionScreen.y);N.addPoint(G.positionScreen.x,G.positionScreen.y);if(L.instersects(N)){J=0;for(z=T.meshMaterial.length;J<z;){P=T.meshMaterial[J++];if(P instanceof
|
||||
THREE.MeshFaceMaterial){S=0;for(X=T.faceMaterial.length;S<X;)(P=T.faceMaterial[S++])&&d(w,x,I,G,T,P,y)}else P&&d(w,x,I,G,T,P,y)}}}}}};
|
||||
THREE.WebGLRenderer=function(a){function b(f,l){var e=c.createProgram();c.attachShader(e,m("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+f));c.attachShader(e,m("vertex","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"+l));c.linkProgram(e);c.getProgramParameter(e,
|
||||
c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(e,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");e.uniforms={};e.attributes={};return e}function d(f,l){if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,f.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 e=0;e<6;++e)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image[e]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+l);c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}function g(f,
|
||||
l){if(!f.__webGLTexture&&f.image.loaded){f.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,f.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,k(f.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,k(f.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,k(f.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,k(f.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+
|
||||
l);c.bindTexture(c.TEXTURE_2D,f.__webGLTexture)}function j(f,l){var e,q,h;e=0;for(q=l.length;e<q;e++){h=l[e];f.uniforms[h]=c.getUniformLocation(f,h)}}function n(f,l){var e,q,h;e=0;for(q=l.length;e<q;e++){h=l[e];f.attributes[h]=c.getAttribLocation(f,h);f.attributes[h]>=0&&c.enableVertexAttribArray(f.attributes[h])}}function m(f,l){var e;if(f=="fragment")e=c.createShader(c.FRAGMENT_SHADER);else if(f=="vertex")e=c.createShader(c.VERTEX_SHADER);c.shaderSource(e,l);c.compileShader(e);if(!c.getShaderParameter(e,
|
||||
c.COMPILE_STATUS)){alert(c.getShaderInfoLog(e));return null}return e}function k(f){switch(f){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 o=document.createElement("canvas"),c,F,D,w=new THREE.Matrix4,x,I=new Float32Array(16),G=new Float32Array(16),L=new Float32Array(16),N=new Float32Array(9),O=new Float32Array(16);a=function(f,l){if(f){var e,q,h,i=pointLights=maxDirLights=maxPointLights=0;e=0;for(q=f.lights.length;e<q;e++){h=f.lights[e];h instanceof THREE.DirectionalLight&&i++;h instanceof THREE.PointLight&&pointLights++}if(pointLights+i<=l){maxDirLights=
|
||||
i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(l*i/(pointLights+i));maxPointLights=l-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:l-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(v){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);
|
||||
c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);F=D=function(f,l){var e=[f?"#define MAX_DIR_LIGHTS "+f:"",l?"#define MAX_POINT_LIGHTS "+l:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",f?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",l?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":
|
||||
"",l?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",l?"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;",
|
||||
f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",f?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",f?"}":"",l?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",l?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",l?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
||||
THREE.Projector=function(){function a(M,u){var e=0,l=1,g=M.z+M.w,q=u.z+u.w,h=-M.z+M.w,i=-u.z+u.w;if(g>=0&&q>=0&&h>=0&&i>=0)return true;else if(g<0&&q<0||h<0&&i<0)return false;else{if(g<0)e=Math.max(e,g/(g-q));else if(q<0)l=Math.min(l,g/(g-q));if(h<0)e=Math.max(e,h/(h-i));else if(i<0)l=Math.min(l,h/(h-i));if(l<e)return false;else{M.lerpSelf(u,e);u.lerpSelf(M,1-l);return true}}}var b=null,d,f,j,m=[],n,k,o=[],c,E,C=[],x=new THREE.Vector4,z=new THREE.Matrix4,H=new THREE.Matrix4,G=new THREE.Vector4,J=
|
||||
new THREE.Vector4,L;this.projectScene=function(M,u){var e,l,g,q,h,i,s,p,D,w,I,S,t,O,B,P,Q;b=[];j=k=E=0;u.autoUpdateMatrix&&u.updateMatrix();z.multiply(u.projectionMatrix,u.matrix);s=M.objects;e=0;for(l=s.length;e<l;e++){p=s[e];p.autoUpdateMatrix&&p.updateMatrix();D=p.matrix;w=p.rotationMatrix;I=p.material;S=p.overdraw;if(p instanceof THREE.Mesh){t=p.geometry.vertices;g=0;for(q=t.length;g<q;g++){O=t[g];O.positionWorld.copy(O.position);D.multiplyVector3(O.positionWorld);B=O.positionScreen;B.copy(O.positionWorld);
|
||||
z.multiplyVector4(B);B.multiplyScalar(1/B.w);O.__visible=B.z>0&&B.z<1}O=p.geometry.faces;g=0;for(q=O.length;g<q;g++){B=O[g];if(B instanceof THREE.Face3){h=t[B.a];i=t[B.b];P=t[B.c];if(h.__visible&&i.__visible&&P.__visible)if(p.doubleSided||p.flipSided!=(P.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(P.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<0){d=m[j]=m[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);
|
||||
d.v3.positionWorld.copy(P.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(P.positionScreen);d.normalWorld.copy(B.normal);w.multiplyVector3(d.normalWorld);d.centroidWorld.copy(B.centroid);D.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);z.multiplyVector3(d.centroidScreen);P=B.vertexNormals;L=d.vertexNormalsWorld;h=0;for(i=P.length;h<i;h++){Q=L[h]=L[h]||new THREE.Vector3;Q.copy(P[h]);w.multiplyVector3(Q)}d.z=
|
||||
d.centroidScreen.z;d.meshMaterial=I;d.faceMaterial=B.material;d.overdraw=S;if(p.geometry.uvs[g]){d.uvs[0]=p.geometry.uvs[g][0];d.uvs[1]=p.geometry.uvs[g][1];d.uvs[2]=p.geometry.uvs[g][2]}b.push(d);j++}}else if(B instanceof THREE.Face4){h=t[B.a];i=t[B.b];P=t[B.c];Q=t[B.d];if(h.__visible&&i.__visible&&P.__visible&&Q.__visible)if(p.doubleSided||p.flipSided!=((Q.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(Q.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<
|
||||
0||(i.positionScreen.x-P.positionScreen.x)*(Q.positionScreen.y-P.positionScreen.y)-(i.positionScreen.y-P.positionScreen.y)*(Q.positionScreen.x-P.positionScreen.x)<0)){d=m[j]=m[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);d.v3.positionWorld.copy(Q.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(Q.positionScreen);d.normalWorld.copy(B.normal);w.multiplyVector3(d.normalWorld);
|
||||
d.centroidWorld.copy(B.centroid);D.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);z.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=I;d.faceMaterial=B.material;d.overdraw=S;if(p.geometry.uvs[g]){d.uvs[0]=p.geometry.uvs[g][0];d.uvs[1]=p.geometry.uvs[g][1];d.uvs[2]=p.geometry.uvs[g][3]}b.push(d);j++;f=m[j]=m[j]||new THREE.RenderableFace3;f.v1.positionWorld.copy(i.positionWorld);f.v2.positionWorld.copy(P.positionWorld);f.v3.positionWorld.copy(Q.positionWorld);
|
||||
f.v1.positionScreen.copy(i.positionScreen);f.v2.positionScreen.copy(P.positionScreen);f.v3.positionScreen.copy(Q.positionScreen);f.normalWorld.copy(d.normalWorld);f.centroidWorld.copy(d.centroidWorld);f.centroidScreen.copy(d.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterial=I;f.faceMaterial=B.material;f.overdraw=S;if(p.geometry.uvs[g]){f.uvs[0]=p.geometry.uvs[g][1];f.uvs[1]=p.geometry.uvs[g][2];f.uvs[2]=p.geometry.uvs[g][3]}b.push(f);j++}}}}else if(p instanceof THREE.Line){H.multiply(z,D);t=p.geometry.vertices;
|
||||
O=t[0];O.positionScreen.copy(O.position);H.multiplyVector4(O.positionScreen);g=1;for(q=t.length;g<q;g++){h=t[g];h.positionScreen.copy(h.position);H.multiplyVector4(h.positionScreen);i=t[g-1];G.copy(h.positionScreen);J.copy(i.positionScreen);if(a(G,J)){G.multiplyScalar(1/G.w);J.multiplyScalar(1/J.w);n=o[k]=o[k]||new THREE.RenderableLine;n.v1.positionScreen.copy(G);n.v2.positionScreen.copy(J);n.z=Math.max(G.z,J.z);n.material=p.material;b.push(n);k++}}}else if(p instanceof THREE.Particle){x.set(p.position.x,
|
||||
p.position.y,p.position.z,1);z.multiplyVector4(x);x.z/=x.w;if(x.z>0&&x.z<1){c=C[E]=C[E]||new THREE.RenderableParticle;c.x=x.x/x.w;c.y=x.y/x.w;c.z=x.z;c.rotation=p.rotation.z;c.scale.x=p.scale.x*Math.abs(c.x-(x.x+u.projectionMatrix.n11)/(x.w+u.projectionMatrix.n14));c.scale.y=p.scale.y*Math.abs(c.y-(x.y+u.projectionMatrix.n22)/(x.w+u.projectionMatrix.n24));c.material=p.material;b.push(c);E++}}}b.sort(function(K,y){return y.z-K.z});return b};this.unprojectVector=function(M,u){var e=new THREE.Matrix4;
|
||||
e.multiply(THREE.Matrix4.makeInvert(u.matrix),THREE.Matrix4.makeInvert(u.projectionMatrix));e.multiplyVector3(M);return M}};
|
||||
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,f,j,m;this.domElement=document.createElement("div");this.setSize=function(n,k){d=n;f=k;j=d/2;m=f/2};this.render=function(n,k){var o,c,E,C,x,z,H,G;a=b.projectScene(n,k);o=0;for(c=a.length;o<c;o++){x=a[o];if(x instanceof THREE.RenderableParticle){H=x.x*j+j;G=x.y*m+m;E=0;for(C=x.material.length;E<C;E++){z=x.material[E];if(z instanceof THREE.ParticleDOMMaterial){z=z.domElement;z.style.left=H+"px";z.style.top=G+"px"}}}}}};
|
||||
THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),f,j,m,n,k=d.getContext("2d"),o=1,c=0,E=null,C=null,x=1,z=Math.min,H=Math.max,G,J,L,M,u,e,l,g,q,h=new THREE.Color,i=new THREE.Color,s=new THREE.Color,p=new THREE.Color,D=new THREE.Color,w,I,S,t,O,B,P,Q,K,y,A=new THREE.Rectangle,T=new THREE.Rectangle,X=new THREE.Rectangle,U=false,R=new THREE.Color,Z=new THREE.Color,ia=new THREE.Color,ja=new THREE.Color,La=Math.PI*2,Y=new THREE.Vector3,na,oa,Ca,ba,pa,
|
||||
va,la=16;na=document.createElement("canvas");na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Ca=oa.getImageData(0,0,2,2);ba=Ca.data;pa=document.createElement("canvas");pa.width=pa.height=la;va=pa.getContext("2d");va.translate(-la/2,-la/2);va.scale(la,la);la--;this.domElement=d;this.autoClear=true;this.setSize=function(fa,wa){f=fa;j=wa;m=f/2;n=j/2;d.width=f;d.height=j;A.set(-m,-n,m,n)};this.clear=function(){if(!T.isEmpty()){T.inflate(1);T.minSelf(A);k.clearRect(T.getX(),
|
||||
T.getY(),T.getWidth(),T.getHeight());T.empty()}};this.render=function(fa,wa){function Ma(r){var V,N,v,F=r.lights;Z.setRGB(0,0,0);ia.setRGB(0,0,0);ja.setRGB(0,0,0);r=0;for(V=F.length;r<V;r++){N=F[r];v=N.color;if(N instanceof THREE.AmbientLight){Z.r+=v.r;Z.g+=v.g;Z.b+=v.b}else if(N instanceof THREE.DirectionalLight){ia.r+=v.r;ia.g+=v.g;ia.b+=v.b}else if(N instanceof THREE.PointLight){ja.r+=v.r;ja.g+=v.g;ja.b+=v.b}}}function xa(r,V,N,v){var F,W,aa,ca,da=r.lights;r=0;for(F=da.length;r<F;r++){W=da[r];
|
||||
aa=W.color;ca=W.intensity;if(W instanceof THREE.DirectionalLight){W=N.dot(W.position)*ca;if(W>0){v.r+=aa.r*W;v.g+=aa.g*W;v.b+=aa.b*W}}else if(W instanceof THREE.PointLight){Y.sub(W.position,V);Y.normalize();W=N.dot(Y)*ca;if(W>0){v.r+=aa.r*W;v.g+=aa.g*W;v.b+=aa.b*W}}}}function Na(r,V,N){if(N.opacity!=0){Da(N.opacity);ya(N.blending);var v,F,W,aa,ca,da;if(N instanceof THREE.ParticleBasicMaterial){if(N.map){aa=N.map;ca=aa.width>>1;da=aa.height>>1;F=V.scale.x*m;W=V.scale.y*n;N=F*ca;v=W*da;X.set(r.x-N,
|
||||
r.y-v,r.x+N,r.y+v);if(!A.instersects(X))return;k.save();k.translate(r.x,r.y);k.rotate(-V.rotation);k.scale(F,-W);k.translate(-ca,-da);k.drawImage(aa,0,0);k.restore()}k.beginPath();k.moveTo(r.x-10,r.y);k.lineTo(r.x+10,r.y);k.moveTo(r.x,r.y-10);k.lineTo(r.x,r.y+10);k.closePath();k.strokeStyle="rgb(255,255,0)";k.stroke()}else if(N instanceof THREE.ParticleCircleMaterial){if(U){R.r=Z.r+ia.r+ja.r;R.g=Z.g+ia.g+ja.g;R.b=Z.b+ia.b+ja.b;h.r=N.color.r*R.r;h.g=N.color.g*R.g;h.b=N.color.b*R.b;h.updateStyleString()}else h.__styleString=
|
||||
N.color.__styleString;N=V.scale.x*m;v=V.scale.y*n;X.set(r.x-N,r.y-v,r.x+N,r.y+v);if(A.instersects(X)){F=h.__styleString;if(C!=F)k.fillStyle=C=F;k.save();k.translate(r.x,r.y);k.rotate(-V.rotation);k.scale(N,v);k.beginPath();k.arc(0,0,1,0,La,true);k.closePath();k.fill();k.restore()}}}}function Oa(r,V,N,v){if(v.opacity!=0){Da(v.opacity);ya(v.blending);k.beginPath();k.moveTo(r.positionScreen.x,r.positionScreen.y);k.lineTo(V.positionScreen.x,V.positionScreen.y);k.closePath();if(v instanceof THREE.LineBasicMaterial){h.__styleString=
|
||||
v.color.__styleString;r=v.linewidth;if(x!=r)k.lineWidth=x=r;r=h.__styleString;if(E!=r)k.strokeStyle=E=r;k.stroke();X.inflate(v.linewidth*2)}}}function Ha(r,V,N,v,F,W){if(F.opacity!=0){Da(F.opacity);ya(F.blending);M=r.positionScreen.x;u=r.positionScreen.y;e=V.positionScreen.x;l=V.positionScreen.y;g=N.positionScreen.x;q=N.positionScreen.y;k.beginPath();k.moveTo(M,u);k.lineTo(e,l);k.lineTo(g,q);k.lineTo(M,u);k.closePath();if(F instanceof THREE.MeshBasicMaterial)if(F.map)F.map.image.loaded&&F.map.mapping instanceof
|
||||
THREE.UVMapping&&qa(M,u,e,l,g,q,F.map.image,v.uvs[0].u,v.uvs[0].v,v.uvs[1].u,v.uvs[1].v,v.uvs[2].u,v.uvs[2].v);else if(F.env_map){if(F.env_map.image.loaded)if(F.env_map.mapping instanceof THREE.SphericalReflectionMapping){r=wa.matrix;Y.copy(v.vertexNormalsWorld[0]);O=(Y.x*r.n11+Y.y*r.n12+Y.z*r.n13)*0.5+0.5;B=-(Y.x*r.n21+Y.y*r.n22+Y.z*r.n23)*0.5+0.5;Y.copy(v.vertexNormalsWorld[1]);P=(Y.x*r.n11+Y.y*r.n12+Y.z*r.n13)*0.5+0.5;Q=-(Y.x*r.n21+Y.y*r.n22+Y.z*r.n23)*0.5+0.5;Y.copy(v.vertexNormalsWorld[2]);K=
|
||||
(Y.x*r.n11+Y.y*r.n12+Y.z*r.n13)*0.5+0.5;y=-(Y.x*r.n21+Y.y*r.n22+Y.z*r.n23)*0.5+0.5;qa(M,u,e,l,g,q,F.env_map.image,O,B,P,Q,K,y)}}else F.wireframe?za(F.color.__styleString,F.wireframe_linewidth):Aa(F.color.__styleString);else if(F instanceof THREE.MeshLambertMaterial){if(F.map&&!F.wireframe){F.map.mapping instanceof THREE.UVMapping&&qa(M,u,e,l,g,q,F.map.image,v.uvs[0].u,v.uvs[0].v,v.uvs[1].u,v.uvs[1].v,v.uvs[2].u,v.uvs[2].v);ya(THREE.SubtractiveBlending)}if(U)if(!F.wireframe&&F.shading==THREE.SmoothShading&&
|
||||
v.vertexNormalsWorld.length==3){i.r=s.r=p.r=Z.r;i.g=s.g=p.g=Z.g;i.b=s.b=p.b=Z.b;xa(W,v.v1.positionWorld,v.vertexNormalsWorld[0],i);xa(W,v.v2.positionWorld,v.vertexNormalsWorld[1],s);xa(W,v.v3.positionWorld,v.vertexNormalsWorld[2],p);D.r=(s.r+p.r)*0.5;D.g=(s.g+p.g)*0.5;D.b=(s.b+p.b)*0.5;t=Ia(i,s,p,D);qa(M,u,e,l,g,q,t,0,0,1,0,0,1)}else{R.r=Z.r;R.g=Z.g;R.b=Z.b;xa(W,v.centroidWorld,v.normalWorld,R);h.r=F.color.r*R.r;h.g=F.color.g*R.g;h.b=F.color.b*R.b;h.updateStyleString();F.wireframe?za(h.__styleString,
|
||||
F.wireframe_linewidth):Aa(h.__styleString)}else F.wireframe?za(F.color.__styleString,F.wireframe_linewidth):Aa(F.color.__styleString)}else if(F instanceof THREE.MeshDepthMaterial){w=F.__2near;I=F.__farPlusNear;S=F.__farMinusNear;i.r=i.g=i.b=1-w/(I-r.positionScreen.z*S);s.r=s.g=s.b=1-w/(I-V.positionScreen.z*S);p.r=p.g=p.b=1-w/(I-N.positionScreen.z*S);D.r=(s.r+p.r)*0.5;D.g=(s.g+p.g)*0.5;D.b=(s.b+p.b)*0.5;t=Ia(i,s,p,D);qa(M,u,e,l,g,q,t,0,0,1,0,0,1)}else if(F instanceof THREE.MeshNormalMaterial){h.r=
|
||||
Ea(v.normalWorld.x);h.g=Ea(v.normalWorld.y);h.b=Ea(v.normalWorld.z);h.updateStyleString();F.wireframe?za(h.__styleString,F.wireframe_linewidth):Aa(h.__styleString)}}}function za(r,V){if(E!=r)k.strokeStyle=E=r;if(x!=V)k.lineWidth=x=V;k.stroke();X.inflate(V*2)}function Aa(r){if(C!=r)k.fillStyle=C=r;k.fill()}function qa(r,V,N,v,F,W,aa,ca,da,ra,ha,sa,ta){var ka,ga;ka=aa.width-1;ga=aa.height-1;ca*=ka;da*=ga;ra*=ka;ha*=ga;sa*=ka;ta*=ga;N-=r;v-=V;F-=r;W-=V;ra-=ca;ha-=da;sa-=ca;ta-=da;ga=1/(ra*ta-sa*ha);
|
||||
ka=(ta*N-ha*F)*ga;ha=(ta*v-ha*W)*ga;N=(ra*F-sa*N)*ga;v=(ra*W-sa*v)*ga;r=r-ka*ca-N*da;V=V-ha*ca-v*da;k.save();k.transform(ka,ha,N,v,r,V);k.clip();k.drawImage(aa,0,0);k.restore()}function Da(r){if(o!=r)k.globalAlpha=o=r}function ya(r){if(c!=r){switch(r){case THREE.NormalBlending:k.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:k.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:k.globalCompositeOperation="darker"}c=r}}function Ia(r,V,N,v){ba[0]=H(0,z(255,
|
||||
~~(r.r*255)));ba[1]=H(0,z(255,~~(r.g*255)));ba[2]=H(0,z(255,~~(r.b*255)));ba[4]=H(0,z(255,~~(V.r*255)));ba[5]=H(0,z(255,~~(V.g*255)));ba[6]=H(0,z(255,~~(V.b*255)));ba[8]=H(0,z(255,~~(N.r*255)));ba[9]=H(0,z(255,~~(N.g*255)));ba[10]=H(0,z(255,~~(N.b*255)));ba[12]=H(0,z(255,~~(v.r*255)));ba[13]=H(0,z(255,~~(v.g*255)));ba[14]=H(0,z(255,~~(v.b*255)));oa.putImageData(Ca,0,0);va.drawImage(na,0,0);return pa}function Ea(r){return r<0?z((1+r)*0.5,0.5):0.5+z(r*0.5,0.5)}function Fa(r,V){var N=V.x-r.x,v=V.y-r.y,
|
||||
F=1/Math.sqrt(N*N+v*v);N*=F;v*=F;V.x+=N;V.y+=v;r.x-=N;r.y-=v}var Ba,Ja,$,ea,ma,Ga,Ka,ua;k.setTransform(1,0,0,-1,m,n);this.autoClear&&this.clear();a=b.projectScene(fa,wa);k.fillStyle="rgba(0, 255, 255, 0.5)";k.fillRect(A.getX(),A.getY(),A.getWidth(),A.getHeight());(U=fa.lights.length>0)&&Ma(fa);Ba=0;for(Ja=a.length;Ba<Ja;Ba++){$=a[Ba];X.empty();if($ instanceof THREE.RenderableParticle){G=$;G.x*=m;G.y*=n;ea=0;for(ma=$.material.length;ea<ma;ea++)Na(G,$,$.material[ea],fa)}else if($ instanceof THREE.RenderableLine){G=
|
||||
$.v1;J=$.v2;G.positionScreen.x*=m;G.positionScreen.y*=n;J.positionScreen.x*=m;J.positionScreen.y*=n;X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(J.positionScreen.x,J.positionScreen.y);if(A.instersects(X)){ea=0;for(ma=$.material.length;ea<ma;)Oa(G,J,$,$.material[ea++],fa)}}else if($ instanceof THREE.RenderableFace3){G=$.v1;J=$.v2;L=$.v3;G.positionScreen.x*=m;G.positionScreen.y*=n;J.positionScreen.x*=m;J.positionScreen.y*=n;L.positionScreen.x*=m;L.positionScreen.y*=n;if($.overdraw){Fa(G.positionScreen,
|
||||
J.positionScreen);Fa(J.positionScreen,L.positionScreen);Fa(L.positionScreen,G.positionScreen)}X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(J.positionScreen.x,J.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);if(A.instersects(X)){ea=0;for(ma=$.meshMaterial.length;ea<ma;){ua=$.meshMaterial[ea++];if(ua instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterial.length;Ga<Ka;)(ua=$.faceMaterial[Ga++])&&Ha(G,J,L,$,ua,fa)}else Ha(G,J,L,$,ua,fa)}}}T.addRectangle(X)}k.lineWidth=
|
||||
1;k.strokeStyle="rgba( 255, 0, 0, 0.5 )";k.strokeRect(T.getX(),T.getY(),T.getWidth(),T.getHeight());k.setTransform(1,0,0,1,0,0)}};
|
||||
THREE.SVGRenderer=function(){function a(B,P,Q){var K,y,A,T;K=0;for(y=B.lights.length;K<y;K++){A=B.lights[K];if(A instanceof THREE.DirectionalLight){T=P.normalWorld.dot(A.position)*A.intensity;if(T>0){Q.r+=A.color.r*T;Q.g+=A.color.g*T;Q.b+=A.color.b*T}}else if(A instanceof THREE.PointLight){i.sub(A.position,P.centroidWorld);i.normalize();T=P.normalWorld.dot(i)*A.intensity;if(T>0){Q.r+=A.color.r*T;Q.g+=A.color.g*T;Q.b+=A.color.b*T}}}}function b(B,P,Q,K,y,A){w=f(I++);w.setAttribute("d","M "+B.positionScreen.x+
|
||||
" "+B.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(y instanceof THREE.MeshBasicMaterial)u.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshLambertMaterial)if(M){e.r=l.r;e.g=l.g;e.b=l.b;a(A,K,e);u.r=y.color.r*e.r;u.g=y.color.g*e.g;u.b=y.color.b*e.b;u.updateStyleString()}else u.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshDepthMaterial){h=1-y.__2near/(y.__farPlusNear-K.z*y.__farMinusNear);
|
||||
u.setRGB(h,h,h)}else y instanceof THREE.MeshNormalMaterial&&u.setRGB(j(K.normalWorld.x),j(K.normalWorld.y),j(K.normalWorld.z));y.wireframe?w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+y.wireframe_linewidth+"; stroke-opacity: "+y.opacity+"; stroke-linecap: "+y.wireframe_linecap+"; stroke-linejoin: "+y.wireframe_linejoin):w.setAttribute("style","fill: "+u.__styleString+"; fill-opacity: "+y.opacity);k.appendChild(w)}function d(B,P,Q,K,y,A,T){w=f(I++);w.setAttribute("d",
|
||||
"M "+B.positionScreen.x+" "+B.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(A instanceof THREE.MeshBasicMaterial)u.__styleString=A.color.__styleString;else if(A instanceof THREE.MeshLambertMaterial)if(M){e.r=l.r;e.g=l.g;e.b=l.b;a(T,y,e);u.r=A.color.r*e.r;u.g=A.color.g*e.g;u.b=A.color.b*e.b;u.updateStyleString()}else u.__styleString=A.color.__styleString;else if(A instanceof THREE.MeshDepthMaterial){h=
|
||||
1-A.__2near/(A.__farPlusNear-y.z*A.__farMinusNear);u.setRGB(h,h,h)}else A instanceof THREE.MeshNormalMaterial&&u.setRGB(j(y.normalWorld.x),j(y.normalWorld.y),j(y.normalWorld.z));A.wireframe?w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+A.wireframe_linewidth+"; stroke-opacity: "+A.opacity+"; stroke-linecap: "+A.wireframe_linecap+"; stroke-linejoin: "+A.wireframe_linejoin):w.setAttribute("style","fill: "+u.__styleString+"; fill-opacity: "+A.opacity);k.appendChild(w)}
|
||||
function f(B){if(s[B]==null){s[B]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&s[B].setAttribute("shape-rendering","crispEdges");return s[B]}return s[B]}function j(B){return B<0?Math.min((1+B)*0.5,0.5):0.5+Math.min(B*0.5,0.5)}var m=null,n=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,E,C,x,z,H,G,J=new THREE.Rectangle,L=new THREE.Rectangle,M=false,u=new THREE.Color(16777215),e=new THREE.Color(16777215),l=new THREE.Color(0),g=new THREE.Color(0),
|
||||
q=new THREE.Color(0),h,i=new THREE.Vector3,s=[],p=[],D=[],w,I,S,t,O=1;this.domElement=k;this.autoClear=true;this.setQuality=function(B){switch(B){case "high":O=1;break;case "low":O=0}};this.setSize=function(B,P){o=B;c=P;E=o/2;C=c/2;k.setAttribute("viewBox",-E+" "+-C+" "+o+" "+c);k.setAttribute("width",o);k.setAttribute("height",c);J.set(-E,-C,E,C)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};this.render=function(B,P){var Q,K,y,A,T,X,U,R;this.autoClear&&this.clear();
|
||||
m=n.projectScene(B,P);t=S=I=0;if(M=B.lights.length>0){U=B.lights;l.setRGB(0,0,0);g.setRGB(0,0,0);q.setRGB(0,0,0);Q=0;for(K=U.length;Q<K;Q++){y=U[Q];A=y.color;if(y instanceof THREE.AmbientLight){l.r+=A.r;l.g+=A.g;l.b+=A.b}else if(y instanceof THREE.DirectionalLight){g.r+=A.r;g.g+=A.g;g.b+=A.b}else if(y instanceof THREE.PointLight){q.r+=A.r;q.g+=A.g;q.b+=A.b}}}Q=0;for(K=m.length;Q<K;Q++){U=m[Q];L.empty();if(U instanceof THREE.RenderableParticle){x=U;x.x*=E;x.y*=-C;y=0;for(A=U.material.length;y<A;y++)if(R=
|
||||
U.material[y]){T=x;X=U;R=R;var Z=S++;if(p[Z]==null){p[Z]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&p[Z].setAttribute("shape-rendering","crispEdges")}w=p[Z];w.setAttribute("cx",T.x);w.setAttribute("cy",T.y);w.setAttribute("r",X.scale.x*E);if(R instanceof THREE.ParticleCircleMaterial){if(M){e.r=l.r+g.r+q.r;e.g=l.g+g.g+q.g;e.b=l.b+g.b+q.b;u.r=R.color.r*e.r;u.g=R.color.g*e.g;u.b=R.color.b*e.b;u.updateStyleString()}else u=R.color;w.setAttribute("style","fill: "+u.__styleString)}k.appendChild(w)}}else if(U instanceof
|
||||
THREE.RenderableLine){x=U.v1;z=U.v2;x.positionScreen.x*=E;x.positionScreen.y*=-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);if(J.instersects(L)){y=0;for(A=U.material.length;y<A;)if(R=U.material[y++]){T=x;X=z;R=R;Z=t++;if(D[Z]==null){D[Z]=document.createElementNS("http://www.w3.org/2000/svg","line");O==0&&D[Z].setAttribute("shape-rendering","crispEdges")}w=D[Z];w.setAttribute("x1",T.positionScreen.x);
|
||||
w.setAttribute("y1",T.positionScreen.y);w.setAttribute("x2",X.positionScreen.x);w.setAttribute("y2",X.positionScreen.y);if(R instanceof THREE.LineBasicMaterial){u.__styleString=R.color.__styleString;w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+R.linewidth+"; stroke-opacity: "+R.opacity+"; stroke-linecap: "+R.linecap+"; stroke-linejoin: "+R.linejoin);k.appendChild(w)}}}}else if(U instanceof THREE.RenderableFace3){x=U.v1;z=U.v2;H=U.v3;x.positionScreen.x*=E;x.positionScreen.y*=
|
||||
-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;H.positionScreen.x*=E;H.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);L.addPoint(H.positionScreen.x,H.positionScreen.y);if(J.instersects(L)){y=0;for(A=U.meshMaterial.length;y<A;){R=U.meshMaterial[y++];if(R instanceof THREE.MeshFaceMaterial){T=0;for(X=U.faceMaterial.length;T<X;)(R=U.faceMaterial[T++])&&b(x,z,H,U,R,B)}else R&&b(x,z,H,U,R,B)}}}else if(U instanceof THREE.RenderableFace4){x=
|
||||
U.v1;z=U.v2;H=U.v3;G=U.v4;x.positionScreen.x*=E;x.positionScreen.y*=-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;H.positionScreen.x*=E;H.positionScreen.y*=-C;G.positionScreen.x*=E;G.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);L.addPoint(H.positionScreen.x,H.positionScreen.y);L.addPoint(G.positionScreen.x,G.positionScreen.y);if(J.instersects(L)){y=0;for(A=U.meshMaterial.length;y<A;){R=U.meshMaterial[y++];if(R instanceof
|
||||
THREE.MeshFaceMaterial){T=0;for(X=U.faceMaterial.length;T<X;)(R=U.faceMaterial[T++])&&d(x,z,H,G,U,R,B)}else R&&d(x,z,H,G,U,R,B)}}}}}};
|
||||
THREE.WebGLRenderer=function(a){function b(e,l){var g=c.createProgram(),q=[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(g,n("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+
|
||||
e));c.attachShader(g,n("vertex",q+l));c.linkProgram(g);c.getProgramParameter(g,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(g,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");g.uniforms={};g.attributes={};return g}function d(e,l){if(e.image.length==6){if(!e.image.__webGLTextureCube&&!e.image.__cubeMapInitialized&&e.image.loadCount==6){e.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,e.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 g=0;g<6;++g)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image[g]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+l);c.bindTexture(c.TEXTURE_CUBE_MAP,
|
||||
e.image.__webGLTextureCube)}}function f(e,l){if(!e.__webGLTexture&&e.image.loaded){e.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,e.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,k(e.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,k(e.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,k(e.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,k(e.min_filter));c.generateMipmap(c.TEXTURE_2D);
|
||||
c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+l);c.bindTexture(c.TEXTURE_2D,e.__webGLTexture)}function j(e,l){var g,q,h;g=0;for(q=l.length;g<q;g++){h=l[g];e.uniforms[h]=c.getUniformLocation(e,h)}}function m(e,l){var g,q,h;g=0;for(q=l.length;g<q;g++){h=l[g];e.attributes[h]=c.getAttribLocation(e,h);e.attributes[h]>=0&&c.enableVertexAttribArray(e.attributes[h])}}function n(e,l){var g;if(e=="fragment")g=c.createShader(c.FRAGMENT_SHADER);else if(e=="vertex")g=c.createShader(c.VERTEX_SHADER);
|
||||
c.shaderSource(g,l);c.compileShader(g);if(!c.getShaderParameter(g,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(g));return null}return g}function k(e){switch(e){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;
|
||||
case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var o=document.createElement("canvas"),c,E,C,x=new THREE.Matrix4,z,H=new Float32Array(16),G=new Float32Array(16),J=new Float32Array(16),L=new Float32Array(9),M=new Float32Array(16);a=function(e,l){if(e){var g,q,h,i=pointLights=maxDirLights=maxPointLights=0;g=0;for(q=e.lights.length;g<q;g++){h=e.lights[g];h instanceof THREE.DirectionalLight&&i++;h instanceof
|
||||
THREE.PointLight&&pointLights++}if(pointLights+i<=l){maxDirLights=i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(l*i/(pointLights+i));maxPointLights=l-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:l-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(u){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);
|
||||
c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);E=C=function(e,l){var g=[e?"#define MAX_DIR_LIGHTS "+e:"",l?"#define MAX_POINT_LIGHTS "+l:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":
|
||||
"",l?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",l?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",l?"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;",
|
||||
e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",l?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",l?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",l?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
||||
"",l?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",l?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",l?"}":"","}\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"),
|
||||
q=[f?"#define MAX_DIR_LIGHTS "+f:"",l?"#define MAX_POINT_LIGHTS "+l:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
||||
f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",l?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
|
||||
q=[e?"#define MAX_DIR_LIGHTS "+e:"",l?"#define MAX_POINT_LIGHTS "+l:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
||||
e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",l?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
|
||||
l?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",l?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",l?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",l?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",l?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",l?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",l?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",l?"float pointSpecularWeight = 0.0;":"",l?"if ( pointDotNormalHalf >= 0.0 )":
|
||||
"",l?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",l?"pointDiffuse += mColor * pointDiffuseWeight;":"",l?"pointSpecular += mSpecular * pointSpecularWeight;":"",l?"}":"",f?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"vec3 dirVector = normalize( lDirection.xyz );":"",f?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
|
||||
"",f?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",f?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",f?"float dirSpecularWeight = 0.0;":"",f?"if ( dirDotNormalHalf >= 0.0 )":"",f?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",f?"dirDiffuse += mColor * dirDiffuseWeight;":"",f?"dirSpecular += mSpecular * dirSpecularWeight;":"",f?"}":"","vec4 totalLight = mAmbient;",f?"totalLight += dirDiffuse + dirSpecular;":"",l?"totalLight += pointDiffuse + pointSpecular;":
|
||||
"",l?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",l?"pointDiffuse += mColor * pointDiffuseWeight;":"",l?"pointSpecular += mSpecular * pointSpecularWeight;":"",l?"}":"",e?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"vec3 dirVector = normalize( lDirection.xyz );":"",e?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
|
||||
"",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",l?"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}"].join("\n");
|
||||
e=b(q,e);c.useProgram(e);j(e,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);f&&j(e,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);l&&j(e,["pointLightNumber","pointLightColor",
|
||||
"pointLightPosition"]);c.uniform1i(e.uniforms.enableMap,0);c.uniform1i(e.uniforms.tMap,0);c.uniform1i(e.uniforms.enableCubeMap,0);c.uniform1i(e.uniforms.tCube,1);c.uniform1i(e.uniforms.mixEnvMap,0);c.uniform1i(e.uniforms.useRefract,0);n(e,["position","normal","uv"]);return e}(a.directional,a.point);this.setSize=function(f,l){o.width=f;o.height=l;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(f,l){var e,q,h,i,s,r=[],
|
||||
M=[],B=[];i=[];s=[];c.uniform1i(f.uniforms.enableLighting,l.length);e=0;for(q=l.length;e<q;e++){h=l[e];if(h instanceof THREE.AmbientLight)r.push(h);else if(h instanceof THREE.DirectionalLight)B.push(h);else h instanceof THREE.PointLight&&M.push(h)}e=h=i=s=0;for(q=r.length;e<q;e++){h+=r[e].color.r;i+=r[e].color.g;s+=r[e].color.b}c.uniform3f(f.uniforms.ambientLightColor,h,i,s);i=[];s=[];e=0;for(q=B.length;e<q;e++){h=B[e];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);
|
||||
s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(B.length){c.uniform1i(f.uniforms.directionalLightNumber,B.length);c.uniform3fv(f.uniforms.directionalLightDirection,s);c.uniform3fv(f.uniforms.directionalLightColor,i)}i=[];s=[];e=0;for(q=M.length;e<q;e++){h=M[e];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(M.length){c.uniform1i(f.uniforms.pointLightNumber,M.length);c.uniform3fv(f.uniforms.pointLightPosition,
|
||||
s);c.uniform3fv(f.uniforms.pointLightColor,i)}};this.createBuffers=function(f,l){var e,q,h,i,s,r,M,B,H=[],Q=[],u=[],R=[],y=[],A=0,E=f.geometry.geometryChunks[l],W;h=false;e=0;for(q=f.material.length;e<q;e++){meshMaterial=f.material[e];if(meshMaterial instanceof THREE.MeshFaceMaterial){s=0;for(W=E.material.length;s<W;s++)if(E.material[s]&&E.material[s].shading!=undefined&&E.material[s].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
|
||||
THREE.SmoothShading){h=true;break}if(h)break}W=h;e=0;for(q=E.faces.length;e<q;e++){h=E.faces[e];i=f.geometry.faces[h];s=i.vertexNormals;faceNormal=i.normal;h=f.geometry.uvs[h];if(i instanceof THREE.Face3){r=f.geometry.vertices[i.a].position;M=f.geometry.vertices[i.b].position;B=f.geometry.vertices[i.c].position;u.push(r.x,r.y,r.z);u.push(M.x,M.y,M.z);u.push(B.x,B.y,B.z);if(s.length==3&&W)for(i=0;i<3;i++)R.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<3;i++)R.push(faceNormal.x,faceNormal.y,faceNormal.z);
|
||||
if(h)for(i=0;i<3;i++)y.push(h[i].u,h[i].v);H.push(A,A+1,A+2);Q.push(A,A+1);Q.push(A,A+2);Q.push(A+1,A+2);A+=3}else if(i instanceof THREE.Face4){r=f.geometry.vertices[i.a].position;M=f.geometry.vertices[i.b].position;B=f.geometry.vertices[i.c].position;i=f.geometry.vertices[i.d].position;u.push(r.x,r.y,r.z);u.push(M.x,M.y,M.z);u.push(B.x,B.y,B.z);u.push(i.x,i.y,i.z);if(s.length==4&&W)for(i=0;i<4;i++)R.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<4;i++)R.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=
|
||||
0;i<4;i++)y.push(h[i].u,h[i].v);H.push(A,A+1,A+2);H.push(A,A+2,A+3);Q.push(A,A+1);Q.push(A,A+2);Q.push(A,A+3);Q.push(A+1,A+2);Q.push(A+2,A+3);A+=4}}if(u.length){E.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(u),c.STATIC_DRAW);E.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(R),c.STATIC_DRAW);if(y.length>0){E.__webGLUVBuffer=c.createBuffer();
|
||||
c.bindBuffer(c.ARRAY_BUFFER,E.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(y),c.STATIC_DRAW)}E.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(H),c.STATIC_DRAW);E.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);E.__webGLFaceCount=H.length;E.__webGLLineCount=Q.length}};this.renderBuffer=
|
||||
function(f,l,e,q){var h,i,s,r,M,B,H,Q,u;if(e instanceof THREE.MeshShaderMaterial){if(!e.program){e.program=b(e.fragment_shader,e.vertex_shader);H=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(u in e.uniforms)H.push(u);j(e.program,H);n(e.program,["position","normal","uv"])}u=e.program}else u=D;if(u!=F){c.useProgram(u);F=u}u==D&&this.setupLights(u,l);this.loadCamera(u,f);this.loadMatrices(u);if(e instanceof THREE.MeshShaderMaterial){s=e.wireframe;
|
||||
r=e.wireframe_linewidth;f=u;l=e.uniforms;var R;for(h in l){Q=l[h].type;H=l[h].value;R=f.uniforms[h];if(Q=="i")c.uniform1i(R,H);else if(Q=="f")c.uniform1f(R,H);else if(Q=="v3")c.uniform3f(R,H.x,H.y,H.z);else if(Q=="c")c.uniform3f(R,H.r,H.g,H.b);else if(Q=="t"){c.uniform1i(R,H);if(Q=l[h].texture)Q.image instanceof Array&&Q.image.length==6?d(Q,H):g(Q,H)}}}if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=e.color;i=e.opacity;s=e.wireframe;
|
||||
r=e.wireframe_linewidth;M=e.map;B=e.env_map;l=e.combine==THREE.MixOperation;f=e.reflectivity;Q=e.env_map&&e.env_map.mapping instanceof THREE.CubeRefractionMapping;H=e.refraction_ratio;c.uniform4f(u.uniforms.mColor,h.r*i,h.g*i,h.b*i,i);c.uniform1i(u.uniforms.mixEnvMap,l);c.uniform1f(u.uniforms.mReflectivity,f);c.uniform1i(u.uniforms.useRefract,Q);c.uniform1f(u.uniforms.mRefractionRatio,H)}if(e instanceof THREE.MeshNormalMaterial){i=e.opacity;c.uniform1f(u.uniforms.mOpacity,i);c.uniform1i(u.uniforms.material,
|
||||
4)}else if(e instanceof THREE.MeshDepthMaterial){i=e.opacity;s=e.wireframe;r=e.wireframe_linewidth;c.uniform1f(u.uniforms.mOpacity,i);c.uniform1f(u.uniforms.m2Near,e.__2near);c.uniform1f(u.uniforms.mFarPlusNear,e.__farPlusNear);c.uniform1f(u.uniforms.mFarMinusNear,e.__farMinusNear);c.uniform1i(u.uniforms.material,3)}else if(e instanceof THREE.MeshPhongMaterial){h=e.ambient;f=e.specular;e=e.shininess;c.uniform4f(u.uniforms.mAmbient,h.r,h.g,h.b,i);c.uniform4f(u.uniforms.mSpecular,f.r,f.g,f.b,i);c.uniform1f(u.uniforms.mShininess,
|
||||
e);c.uniform1i(u.uniforms.material,2)}else if(e instanceof THREE.MeshLambertMaterial)c.uniform1i(u.uniforms.material,1);else if(e instanceof THREE.MeshBasicMaterial)c.uniform1i(u.uniforms.material,0);else if(e instanceof THREE.MeshCubeMaterial){c.uniform1i(u.uniforms.material,5);B=e.env_map}if(M){g(M,0);c.uniform1i(u.uniforms.tMap,0);c.uniform1i(u.uniforms.enableMap,1)}else c.uniform1i(u.uniforms.enableMap,0);if(B){d(B,1);c.uniform1i(u.uniforms.tCube,1);c.uniform1i(u.uniforms.enableCubeMap,1)}else c.uniform1i(u.uniforms.enableCubeMap,
|
||||
0);i=u.attributes;c.bindBuffer(c.ARRAY_BUFFER,q.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,q.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.uv>=0)if(q.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(s){c.lineWidth(r);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);
|
||||
c.drawElements(c.LINES,q.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,q.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(f,l,e,q,h,i){var s,r,M,B,H;M=0;for(B=e.material.length;M<B;M++){s=e.material[M];if(s instanceof THREE.MeshFaceMaterial){s=0;for(r=q.material.length;s<r;s++)if((H=q.material[s])&&H.blending==h&&H.opacity<1==i){this.setBlending(H.blending);this.renderBuffer(f,l,H,q)}}else if((H=s)&&H.blending==
|
||||
h&&H.opacity<1==i){this.setBlending(H.blending);this.renderBuffer(f,l,H,q)}}};this.render=function(f,l){var e,q,h,i,s=f.lights;this.initWebGLObjects(f);this.autoClear&&this.clear();l.autoUpdateMatrix&&l.updateMatrix();e=0;for(q=f.__webGLObjects.length;e<q;e++){h=f.__webGLObjects[e];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,l);this.renderPass(l,s,i,h,THREE.NormalBlending,false)}}e=0;for(q=f.__webGLObjects.length;e<q;e++){h=f.__webGLObjects[e];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,
|
||||
l);this.renderPass(l,s,i,h,THREE.AdditiveBlending,false);this.renderPass(l,s,i,h,THREE.SubtractiveBlending,false);this.renderPass(l,s,i,h,THREE.AdditiveBlending,true);this.renderPass(l,s,i,h,THREE.SubtractiveBlending,true);this.renderPass(l,s,i,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(f){var l,e,q,h,i,s;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={}}l=0;for(e=f.objects.length;l<e;l++){q=f.objects[l];if(f.__webGLObjectsMap[q.id]==undefined)f.__webGLObjectsMap[q.id]=
|
||||
{};s=f.__webGLObjectsMap[q.id];if(q instanceof THREE.Mesh)for(i in q.geometry.geometryChunks){h=q.geometry.geometryChunks[i];h.__webGLVertexBuffer||this.createBuffers(q,i);if(s[i]==undefined){h={buffer:h,object:q};f.__webGLObjects.push(h);s[i]=1}}}};this.removeObject=function(f,l){var e,q;for(e=f.__webGLObjects.length-1;e>=0;e--){q=f.__webGLObjects[e].object;l==q&&f.__webGLObjects.splice(e,1)}};this.setupMatrices=function(f,l){f.autoUpdateMatrix&&f.updateMatrix();w.multiply(l.matrix,f.matrix);I.set(l.matrix.flatten());
|
||||
G.set(w.flatten());L.set(l.projectionMatrix.flatten());x=THREE.Matrix4.makeInvert3x3(w).transpose();N.set(x.m);O.set(f.matrix.flatten())};this.loadMatrices=function(f){c.uniformMatrix4fv(f.uniforms.viewMatrix,false,I);c.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,G);c.uniformMatrix4fv(f.uniforms.projectionMatrix,false,L);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,N);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,O)};this.loadCamera=function(f,l){c.uniform3f(f.uniforms.cameraPosition,
|
||||
l.position.x,l.position.y,l.position.z)};this.setBlending=function(f){switch(f){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(f,l){if(f){!l||l=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(f=="back")c.cullFace(c.BACK);else f=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);
|
||||
c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};
|
||||
THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
|
||||
g=b(q,g);c.useProgram(g);j(g,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);e&&j(g,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);l&&j(g,["pointLightNumber","pointLightColor",
|
||||
"pointLightPosition"]);c.uniform1i(g.uniforms.enableMap,0);c.uniform1i(g.uniforms.tMap,0);c.uniform1i(g.uniforms.enableCubeMap,0);c.uniform1i(g.uniforms.tCube,1);c.uniform1i(g.uniforms.mixEnvMap,0);c.uniform1i(g.uniforms.useRefract,0);m(g,["position","normal","uv"]);return g}(a.directional,a.point);this.setSize=function(e,l){o.width=e;o.height=l;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,l){var g,q,h,i,s,p=[],
|
||||
D=[],w=[];i=[];s=[];c.uniform1i(e.uniforms.enableLighting,l.length);g=0;for(q=l.length;g<q;g++){h=l[g];if(h instanceof THREE.AmbientLight)p.push(h);else if(h instanceof THREE.DirectionalLight)w.push(h);else h instanceof THREE.PointLight&&D.push(h)}g=h=i=s=0;for(q=p.length;g<q;g++){h+=p[g].color.r;i+=p[g].color.g;s+=p[g].color.b}c.uniform3f(e.uniforms.ambientLightColor,h,i,s);i=[];s=[];g=0;for(q=w.length;g<q;g++){h=w[g];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);
|
||||
s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(w.length){c.uniform1i(e.uniforms.directionalLightNumber,w.length);c.uniform3fv(e.uniforms.directionalLightDirection,s);c.uniform3fv(e.uniforms.directionalLightColor,i)}i=[];s=[];g=0;for(q=D.length;g<q;g++){h=D[g];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(D.length){c.uniform1i(e.uniforms.pointLightNumber,D.length);c.uniform3fv(e.uniforms.pointLightPosition,
|
||||
s);c.uniform3fv(e.uniforms.pointLightColor,i)}};this.createBuffers=function(e,l){var g,q,h,i,s,p,D,w,I,S=[],t=[],O=[],B=[],P=[],Q=[],K=0,y=e.geometry.geometryChunks[l],A;h=false;g=0;for(q=e.material.length;g<q;g++){meshMaterial=e.material[g];if(meshMaterial instanceof THREE.MeshFaceMaterial){s=0;for(A=y.material.length;s<A;s++)if(y.material[s]&&y.material[s].shading!=undefined&&y.material[s].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
|
||||
THREE.SmoothShading){h=true;break}if(h)break}A=h;g=0;for(q=y.faces.length;g<q;g++){h=y.faces[g];i=e.geometry.faces[h];s=i.vertexNormals;faceNormal=i.normal;h=e.geometry.uvs[h];if(i instanceof THREE.Face3){p=e.geometry.vertices[i.a].position;D=e.geometry.vertices[i.b].position;w=e.geometry.vertices[i.c].position;O.push(p.x,p.y,p.z);O.push(D.x,D.y,D.z);O.push(w.x,w.y,w.z);if(e.geometry.hasTangents){p=e.geometry.vertices[i.a].tangent;D=e.geometry.vertices[i.b].tangent;w=e.geometry.vertices[i.c].tangent;
|
||||
P.push(p.x,p.y,p.z,p.w);P.push(D.x,D.y,D.z,D.w);P.push(w.x,w.y,w.z,w.w)}if(s.length==3&&A)for(i=0;i<3;i++)B.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<3;i++)B.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=0;i<3;i++)Q.push(h[i].u,h[i].v);S.push(K,K+1,K+2);t.push(K,K+1);t.push(K,K+2);t.push(K+1,K+2);K+=3}else if(i instanceof THREE.Face4){p=e.geometry.vertices[i.a].position;D=e.geometry.vertices[i.b].position;w=e.geometry.vertices[i.c].position;I=e.geometry.vertices[i.d].position;O.push(p.x,
|
||||
p.y,p.z);O.push(D.x,D.y,D.z);O.push(w.x,w.y,w.z);O.push(I.x,I.y,I.z);if(e.geometry.hasTangents){p=e.geometry.vertices[i.a].tangent;D=e.geometry.vertices[i.b].tangent;w=e.geometry.vertices[i.c].tangent;i=e.geometry.vertices[i.d].tangent;P.push(p.x,p.y,p.z,p.w);P.push(D.x,D.y,D.z,D.w);P.push(w.x,w.y,w.z,w.w);P.push(i.x,i.y,i.z,i.w)}if(s.length==4&&A)for(i=0;i<4;i++)B.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<4;i++)B.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=0;i<4;i++)Q.push(h[i].u,h[i].v);
|
||||
S.push(K,K+1,K+2);S.push(K,K+2,K+3);t.push(K,K+1);t.push(K,K+2);t.push(K,K+3);t.push(K+1,K+2);t.push(K+2,K+3);K+=4}}if(O.length){y.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW);y.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(B),c.STATIC_DRAW);if(e.geometry.hasTangents){y.__webGLTangentBuffer=c.createBuffer();
|
||||
c.bindBuffer(c.ARRAY_BUFFER,y.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(P),c.STATIC_DRAW)}if(Q.length>0){y.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(Q),c.STATIC_DRAW)}y.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(S),c.STATIC_DRAW);y.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
|
||||
y.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(t),c.STATIC_DRAW);y.__webGLFaceCount=S.length;y.__webGLLineCount=t.length}};this.renderBuffer=function(e,l,g,q){var h,i,s,p,D,w,I,S,t;if(g instanceof THREE.MeshShaderMaterial){if(!g.program){g.program=b(g.fragment_shader,g.vertex_shader);I=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(t in g.uniforms)I.push(t);j(g.program,I);m(g.program,["position","normal","uv","tangent"])}t=
|
||||
g.program}else t=C;if(t!=E){c.useProgram(t);E=t}t==C&&this.setupLights(t,l);this.loadCamera(t,e);this.loadMatrices(t);if(g instanceof THREE.MeshShaderMaterial){s=g.wireframe;p=g.wireframe_linewidth;e=t;l=g.uniforms;var O;for(h in l){S=l[h].type;I=l[h].value;O=e.uniforms[h];if(S=="i")c.uniform1i(O,I);else if(S=="f")c.uniform1f(O,I);else if(S=="v3")c.uniform3f(O,I.x,I.y,I.z);else if(S=="c")c.uniform3f(O,I.r,I.g,I.b);else if(S=="t"){c.uniform1i(O,I);if(S=l[h].texture)S.image instanceof Array&&S.image.length==
|
||||
6?d(S,I):f(S,I)}}}if(g instanceof THREE.MeshPhongMaterial||g instanceof THREE.MeshLambertMaterial||g instanceof THREE.MeshBasicMaterial){h=g.color;i=g.opacity;s=g.wireframe;p=g.wireframe_linewidth;D=g.map;w=g.env_map;l=g.combine==THREE.MixOperation;e=g.reflectivity;S=g.env_map&&g.env_map.mapping instanceof THREE.CubeRefractionMapping;I=g.refraction_ratio;c.uniform4f(t.uniforms.mColor,h.r*i,h.g*i,h.b*i,i);c.uniform1i(t.uniforms.mixEnvMap,l);c.uniform1f(t.uniforms.mReflectivity,e);c.uniform1i(t.uniforms.useRefract,
|
||||
S);c.uniform1f(t.uniforms.mRefractionRatio,I)}if(g instanceof THREE.MeshNormalMaterial){i=g.opacity;c.uniform1f(t.uniforms.mOpacity,i);c.uniform1i(t.uniforms.material,4)}else if(g instanceof THREE.MeshDepthMaterial){i=g.opacity;s=g.wireframe;p=g.wireframe_linewidth;c.uniform1f(t.uniforms.mOpacity,i);c.uniform1f(t.uniforms.m2Near,g.__2near);c.uniform1f(t.uniforms.mFarPlusNear,g.__farPlusNear);c.uniform1f(t.uniforms.mFarMinusNear,g.__farMinusNear);c.uniform1i(t.uniforms.material,3)}else if(g instanceof
|
||||
THREE.MeshPhongMaterial){h=g.ambient;e=g.specular;g=g.shininess;c.uniform4f(t.uniforms.mAmbient,h.r,h.g,h.b,i);c.uniform4f(t.uniforms.mSpecular,e.r,e.g,e.b,i);c.uniform1f(t.uniforms.mShininess,g);c.uniform1i(t.uniforms.material,2)}else if(g instanceof THREE.MeshLambertMaterial)c.uniform1i(t.uniforms.material,1);else if(g instanceof THREE.MeshBasicMaterial)c.uniform1i(t.uniforms.material,0);else if(g instanceof THREE.MeshCubeMaterial){c.uniform1i(t.uniforms.material,5);w=g.env_map}if(D){f(D,0);c.uniform1i(t.uniforms.tMap,
|
||||
0);c.uniform1i(t.uniforms.enableMap,1)}else c.uniform1i(t.uniforms.enableMap,0);if(w){d(w,1);c.uniform1i(t.uniforms.tCube,1);c.uniform1i(t.uniforms.enableCubeMap,1)}else c.uniform1i(t.uniforms.enableCubeMap,0);i=t.attributes;c.bindBuffer(c.ARRAY_BUFFER,q.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,q.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLTangentBuffer);
|
||||
c.vertexAttribPointer(i.tangent,4,c.FLOAT,false,0,0)}if(i.uv>=0)if(q.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(s){c.lineWidth(p);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);c.drawElements(c.LINES,q.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,q.__webGLFaceCount,c.UNSIGNED_SHORT,
|
||||
0)}};this.renderPass=function(e,l,g,q,h,i){var s,p,D,w,I;D=0;for(w=g.material.length;D<w;D++){s=g.material[D];if(s instanceof THREE.MeshFaceMaterial){s=0;for(p=q.material.length;s<p;s++)if((I=q.material[s])&&I.blending==h&&I.opacity<1==i){this.setBlending(I.blending);this.renderBuffer(e,l,I,q)}}else if((I=s)&&I.blending==h&&I.opacity<1==i){this.setBlending(I.blending);this.renderBuffer(e,l,I,q)}}};this.render=function(e,l){var g,q,h,i,s=e.lights;this.initWebGLObjects(e);this.autoClear&&this.clear();
|
||||
l.autoUpdateMatrix&&l.updateMatrix();g=0;for(q=e.__webGLObjects.length;g<q;g++){h=e.__webGLObjects[g];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,l);this.renderPass(l,s,i,h,THREE.NormalBlending,false)}}g=0;for(q=e.__webGLObjects.length;g<q;g++){h=e.__webGLObjects[g];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,l);this.renderPass(l,s,i,h,THREE.AdditiveBlending,false);this.renderPass(l,s,i,h,THREE.SubtractiveBlending,false);this.renderPass(l,s,i,h,THREE.AdditiveBlending,true);
|
||||
this.renderPass(l,s,i,h,THREE.SubtractiveBlending,true);this.renderPass(l,s,i,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var l,g,q,h,i,s;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}l=0;for(g=e.objects.length;l<g;l++){q=e.objects[l];if(e.__webGLObjectsMap[q.id]==undefined)e.__webGLObjectsMap[q.id]={};s=e.__webGLObjectsMap[q.id];if(q instanceof THREE.Mesh)for(i in q.geometry.geometryChunks){h=q.geometry.geometryChunks[i];h.__webGLVertexBuffer||this.createBuffers(q,
|
||||
i);if(s[i]==undefined){h={buffer:h,object:q};e.__webGLObjects.push(h);s[i]=1}}}};this.removeObject=function(e,l){var g,q;for(g=e.__webGLObjects.length-1;g>=0;g--){q=e.__webGLObjects[g].object;l==q&&e.__webGLObjects.splice(g,1)}};this.setupMatrices=function(e,l){e.autoUpdateMatrix&&e.updateMatrix();x.multiply(l.matrix,e.matrix);H.set(l.matrix.flatten());G.set(x.flatten());J.set(l.projectionMatrix.flatten());z=THREE.Matrix4.makeInvert3x3(x).transpose();L.set(z.m);M.set(e.matrix.flatten())};this.loadMatrices=
|
||||
function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,H);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,G);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,J);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,L);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,M)};this.loadCamera=function(e,l){c.uniform3f(e.uniforms.cameraPosition,l.position.x,l.position.y,l.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);
|
||||
break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,l){if(e){!l||l=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);else e=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
|
||||
THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
|
||||
THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
|
||||
|
||||
+142
-134
@@ -12,44 +12,47 @@ THREE.Vector4=function(a,b,d,e){this.x=a||0;this.y=b||0;this.z=d||0;this.w=e||1}
|
||||
THREE.Vector4.prototype={set:function(a,b,d,e){this.x=a;this.y=b;this.z=d;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
|
||||
return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
|
||||
THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
|
||||
THREE.Ray.prototype={intersectScene:function(a){var b,d,e=a.objects,g=[];a=0;for(b=e.length;a<b;a++){d=e[a];if(d instanceof THREE.Mesh)g=g.concat(this.intersectObject(d))}g.sort(function(j,l){return j.distance-l.distance});return g},intersectObject:function(a){function b(H,I,z,m){m=m.clone().subSelf(I);z=z.clone().subSelf(I);var h=H.clone().subSelf(I);H=m.dot(m);I=m.dot(z);m=m.dot(h);var n=z.dot(z);z=z.dot(h);h=1/(H*n-I*I);n=(n*m-I*z)*h;H=(H*z-I*m)*h;return n>0&&H>0&&n+H<1}var d,e,g,j,l,f,q,c,t,D,
|
||||
r,u=a.geometry,v=u.vertices,w=[];d=0;for(e=u.faces.length;d<e;d++){g=u.faces[d];D=this.origin.clone();r=this.direction.clone();j=a.matrix.multiplyVector3(v[g.a].position.clone());l=a.matrix.multiplyVector3(v[g.b].position.clone());f=a.matrix.multiplyVector3(v[g.c].position.clone());q=g instanceof THREE.Face4?a.matrix.multiplyVector3(v[g.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(g.normal.clone());t=r.dot(c);if(t<0){c=c.dot((new THREE.Vector3).sub(j,D))/t;D=D.addSelf(r.multiplyScalar(c));
|
||||
if(g instanceof THREE.Face3){if(b(D,j,l,f)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};w.push(g)}}else if(g instanceof THREE.Face4)if(b(D,j,l,q)||b(D,l,f,q)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};w.push(g)}}}return w}};
|
||||
THREE.Rectangle=function(){function a(){j=e-b;l=g-d}var b,d,e,g,j,l,f=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return j};this.getHeight=function(){return l};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return e};this.getBottom=function(){return g};this.set=function(q,c,t,D){f=false;b=q;d=c;e=t;g=D;a()};this.addPoint=function(q,c){if(f){f=false;b=q;d=c;e=q;g=c}else{b=Math.min(b,q);d=Math.min(d,c);e=Math.max(e,
|
||||
q);g=Math.max(g,c)}a()};this.addRectangle=function(q){if(f){f=false;b=q.getLeft();d=q.getTop();e=q.getRight();g=q.getBottom()}else{b=Math.min(b,q.getLeft());d=Math.min(d,q.getTop());e=Math.max(e,q.getRight());g=Math.max(g,q.getBottom())}a()};this.inflate=function(q){b-=q;d-=q;e+=q;g+=q;a()};this.minSelf=function(q){b=Math.max(b,q.getLeft());d=Math.max(d,q.getTop());e=Math.min(e,q.getRight());g=Math.min(g,q.getBottom());a()};this.instersects=function(q){return Math.min(e,q.getRight())-Math.max(b,q.getLeft())>=
|
||||
0&&Math.min(g,q.getBottom())-Math.max(d,q.getTop())>=0};this.empty=function(){f=true;g=e=d=b=0;a()};this.isEmpty=function(){return f};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+d+", bottom: "+g+", width: "+j+", height: "+l+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
|
||||
THREE.Ray.prototype={intersectScene:function(a){var b,d,e=a.objects,g=[];a=0;for(b=e.length;a<b;a++){d=e[a];if(d instanceof THREE.Mesh)g=g.concat(this.intersectObject(d))}g.sort(function(j,l){return j.distance-l.distance});return g},intersectObject:function(a){function b(G,H,A,m){m=m.clone().subSelf(H);A=A.clone().subSelf(H);var h=G.clone().subSelf(H);G=m.dot(m);H=m.dot(A);m=m.dot(h);var o=A.dot(A);A=A.dot(h);h=1/(G*o-H*H);o=(o*m-H*A)*h;G=(G*A-H*m)*h;return o>0&&G>0&&o+G<1}var d,e,g,j,l,f,p,c,t,C,
|
||||
r,u=a.geometry,v=u.vertices,w=[];d=0;for(e=u.faces.length;d<e;d++){g=u.faces[d];C=this.origin.clone();r=this.direction.clone();j=a.matrix.multiplyVector3(v[g.a].position.clone());l=a.matrix.multiplyVector3(v[g.b].position.clone());f=a.matrix.multiplyVector3(v[g.c].position.clone());p=g instanceof THREE.Face4?a.matrix.multiplyVector3(v[g.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(g.normal.clone());t=r.dot(c);if(t<0){c=c.dot((new THREE.Vector3).sub(j,C))/t;C=C.addSelf(r.multiplyScalar(c));
|
||||
if(g instanceof THREE.Face3){if(b(C,j,l,f)){g={distance:this.origin.distanceTo(C),point:C,face:g,object:a};w.push(g)}}else if(g instanceof THREE.Face4)if(b(C,j,l,p)||b(C,l,f,p)){g={distance:this.origin.distanceTo(C),point:C,face:g,object:a};w.push(g)}}}return w}};
|
||||
THREE.Rectangle=function(){function a(){j=e-b;l=g-d}var b,d,e,g,j,l,f=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return j};this.getHeight=function(){return l};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return e};this.getBottom=function(){return g};this.set=function(p,c,t,C){f=false;b=p;d=c;e=t;g=C;a()};this.addPoint=function(p,c){if(f){f=false;b=p;d=c;e=p;g=c}else{b=Math.min(b,p);d=Math.min(d,c);e=Math.max(e,
|
||||
p);g=Math.max(g,c)}a()};this.addRectangle=function(p){if(f){f=false;b=p.getLeft();d=p.getTop();e=p.getRight();g=p.getBottom()}else{b=Math.min(b,p.getLeft());d=Math.min(d,p.getTop());e=Math.max(e,p.getRight());g=Math.max(g,p.getBottom())}a()};this.inflate=function(p){b-=p;d-=p;e+=p;g+=p;a()};this.minSelf=function(p){b=Math.max(b,p.getLeft());d=Math.max(d,p.getTop());e=Math.min(e,p.getRight());g=Math.min(g,p.getBottom());a()};this.instersects=function(p){return Math.min(e,p.getRight())-Math.max(b,p.getLeft())>=
|
||||
0&&Math.min(g,p.getBottom())-Math.max(d,p.getTop())>=0};this.empty=function(){f=true;g=e=d=b=0;a()};this.isEmpty=function(){return f};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+d+", bottom: "+g+", width: "+j+", height: "+l+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
|
||||
THREE.Matrix4=function(){};
|
||||
THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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},lookAt:function(a,b,d){var e=new THREE.Vector3,g=new THREE.Vector3,j=new THREE.Vector3;j.sub(a,b).normalize();e.cross(d,j).normalize();g.cross(j,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=g.x;this.n22=g.y;this.n23=g.z;this.n24=-g.dot(a);this.n31=j.x;this.n32=j.y;this.n33=j.z;this.n34=-j.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,e=a.z,g=1/(this.n41*b+this.n42*
|
||||
d+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*e+this.n14)*g;a.y=(this.n21*b+this.n22*d+this.n23*e+this.n24)*g;a.z=(this.n31*b+this.n32*d+this.n33*e+this.n34)*g;return a},multiplyVector4:function(a){var b=a.x,d=a.y,e=a.z,g=a.w;a.x=this.n11*b+this.n12*d+this.n13*e+this.n14*g;a.y=this.n21*b+this.n22*d+this.n23*e+this.n24*g;a.z=this.n31*b+this.n32*d+this.n33*e+this.n34*g;a.w=this.n41*b+this.n42*d+this.n43*e+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 d=a.n11,e=a.n12,g=a.n13,j=a.n14,l=a.n21,f=a.n22,q=a.n23,c=a.n24,t=a.n31,D=a.n32,r=a.n33,u=a.n34,v=a.n41,w=a.n42,H=a.n43,I=a.n44,z=b.n11,m=b.n12,h=b.n13,n=b.n14,i=b.n21,y=b.n22,k=b.n23,o=b.n24,B=b.n31,A=b.n32,P=b.n33,J=b.n34,Q=b.n41,T=b.n42,E=b.n43,
|
||||
U=b.n44;this.n11=d*z+e*i+g*B+j*Q;this.n12=d*m+e*y+g*A+j*T;this.n13=d*h+e*k+g*P+j*E;this.n14=d*n+e*o+g*J+j*U;this.n21=l*z+f*i+q*B+c*Q;this.n22=l*m+f*y+q*A+c*T;this.n23=l*h+f*k+q*P+c*E;this.n24=l*n+f*o+q*J+c*U;this.n31=t*z+D*i+r*B+u*Q;this.n32=t*m+D*y+r*A+u*T;this.n33=t*h+D*k+r*P+u*E;this.n34=t*n+D*o+r*J+u*U;this.n41=v*z+w*i+H*B+I*Q;this.n42=v*m+w*y+H*A+I*T;this.n43=v*h+w*k+H*P+I*E;this.n44=v*n+w*o+H*J+I*U},multiplySelf:function(a){var b=this.n11,d=this.n12,e=this.n13,g=this.n14,j=this.n21,l=this.n22,
|
||||
f=this.n23,q=this.n24,c=this.n31,t=this.n32,D=this.n33,r=this.n34,u=this.n41,v=this.n42,w=this.n43,H=this.n44;this.n11=b*a.n11+d*a.n21+e*a.n31+g*a.n41;this.n12=b*a.n12+d*a.n22+e*a.n32+g*a.n42;this.n13=b*a.n13+d*a.n23+e*a.n33+g*a.n43;this.n14=b*a.n14+d*a.n24+e*a.n34+g*a.n44;this.n21=j*a.n11+l*a.n21+f*a.n31+q*a.n41;this.n22=j*a.n12+l*a.n22+f*a.n32+q*a.n42;this.n23=j*a.n13+l*a.n23+f*a.n33+q*a.n43;this.n24=j*a.n14+l*a.n24+f*a.n34+q*a.n44;this.n31=c*a.n11+t*a.n21+D*a.n31+r*a.n41;this.n32=c*a.n12+t*a.n22+
|
||||
D*a.n32+r*a.n42;this.n33=c*a.n13+t*a.n23+D*a.n33+r*a.n43;this.n34=c*a.n14+t*a.n24+D*a.n34+r*a.n44;this.n41=u*a.n11+v*a.n21+w*a.n31+H*a.n41;this.n42=u*a.n12+v*a.n22+w*a.n32+H*a.n42;this.n43=u*a.n13+v*a.n23+w*a.n33+H*a.n43;this.n44=u*a.n14+v*a.n24+w*a.n34+H*a.n44},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},determinant:function(){return this.n14*
|
||||
a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,e=a.n12,g=a.n13,j=a.n14,l=a.n21,f=a.n22,p=a.n23,c=a.n24,t=a.n31,C=a.n32,r=a.n33,u=a.n34,v=a.n41,w=a.n42,G=a.n43,H=a.n44,A=b.n11,m=b.n12,h=b.n13,o=b.n14,i=b.n21,x=b.n22,k=b.n23,n=b.n24,B=b.n31,y=b.n32,L=b.n33,F=b.n34,O=b.n41,V=b.n42,E=b.n43,
|
||||
S=b.n44;this.n11=d*A+e*i+g*B+j*O;this.n12=d*m+e*x+g*y+j*V;this.n13=d*h+e*k+g*L+j*E;this.n14=d*o+e*n+g*F+j*S;this.n21=l*A+f*i+p*B+c*O;this.n22=l*m+f*x+p*y+c*V;this.n23=l*h+f*k+p*L+c*E;this.n24=l*o+f*n+p*F+c*S;this.n31=t*A+C*i+r*B+u*O;this.n32=t*m+C*x+r*y+u*V;this.n33=t*h+C*k+r*L+u*E;this.n34=t*o+C*n+r*F+u*S;this.n41=v*A+w*i+G*B+H*O;this.n42=v*m+w*x+G*y+H*V;this.n43=v*h+w*k+G*L+H*E;this.n44=v*o+w*n+G*F+H*S},multiplySelf:function(a){var b=this.n11,d=this.n12,e=this.n13,g=this.n14,j=this.n21,l=this.n22,
|
||||
f=this.n23,p=this.n24,c=this.n31,t=this.n32,C=this.n33,r=this.n34,u=this.n41,v=this.n42,w=this.n43,G=this.n44;this.n11=b*a.n11+d*a.n21+e*a.n31+g*a.n41;this.n12=b*a.n12+d*a.n22+e*a.n32+g*a.n42;this.n13=b*a.n13+d*a.n23+e*a.n33+g*a.n43;this.n14=b*a.n14+d*a.n24+e*a.n34+g*a.n44;this.n21=j*a.n11+l*a.n21+f*a.n31+p*a.n41;this.n22=j*a.n12+l*a.n22+f*a.n32+p*a.n42;this.n23=j*a.n13+l*a.n23+f*a.n33+p*a.n43;this.n24=j*a.n14+l*a.n24+f*a.n34+p*a.n44;this.n31=c*a.n11+t*a.n21+C*a.n31+r*a.n41;this.n32=c*a.n12+t*a.n22+
|
||||
C*a.n32+r*a.n42;this.n33=c*a.n13+t*a.n23+C*a.n33+r*a.n43;this.n34=c*a.n14+t*a.n24+C*a.n34+r*a.n44;this.n41=u*a.n11+v*a.n21+w*a.n31+G*a.n41;this.n42=u*a.n12+v*a.n22+w*a.n32+G*a.n42;this.n43=u*a.n13+v*a.n23+w*a.n33+G*a.n43;this.n44=u*a.n14+v*a.n24+w*a.n34+G*a.n44},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},determinant:function(){return this.n14*
|
||||
this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
|
||||
this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,e){var g=b[d];b[d]=b[e];b[e]=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,d){var e=new THREE.Matrix4;e.n14=a;e.n24=b;e.n34=d;return e};THREE.Matrix4.scaleMatrix=function(a,b,d){var e=new THREE.Matrix4;e.n11=a;e.n22=b;e.n33=d;return e};
|
||||
THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
|
||||
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,e=Math.cos(b),g=Math.sin(b),j=1-e,l=a.x,f=a.y,q=a.z;d.n11=j*l*l+e;d.n12=j*l*f-g*q;d.n13=j*l*q+g*f;d.n21=j*l*f+g*q;d.n22=j*f*f+e;d.n23=j*f*q-g*l;d.n31=j*l*q-g*f;d.n32=j*f*q+g*l;d.n33=j*q*q+e;return d};
|
||||
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,e=Math.cos(b),g=Math.sin(b),j=1-e,l=a.x,f=a.y,p=a.z;d.n11=j*l*l+e;d.n12=j*l*f-g*p;d.n13=j*l*p+g*f;d.n21=j*l*f+g*p;d.n22=j*f*f+e;d.n23=j*f*p-g*l;d.n31=j*l*p-g*f;d.n32=j*f*p+g*l;d.n33=j*p*p+e;return d};
|
||||
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 d=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],l=b[10]*b[0]-b[2]*b[8],f=-b[6]*b[0]+b[2]*b[4],q=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],t=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*j+b[2]*q;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*e;a.m[2]=b*g;a.m[3]=b*j;a.m[4]=b*l;a.m[5]=b*f;a.m[6]=b*q;a.m[7]=b*c;a.m[8]=b*t;return a};
|
||||
THREE.Matrix4.makeFrustum=function(a,b,d,e,g,j){var l,f,q;l=new THREE.Matrix4;f=2*g/(b-a);q=2*g/(e-d);a=(b+a)/(b-a);d=(e+d)/(e-d);e=-(j+g)/(j-g);g=-2*j*g/(j-g);l.n11=f;l.n12=0;l.n13=a;l.n14=0;l.n21=0;l.n22=q;l.n23=d;l.n24=0;l.n31=0;l.n32=0;l.n33=e;l.n34=g;l.n41=0;l.n42=0;l.n43=-1;l.n44=0;return l};THREE.Matrix4.makePerspective=function(a,b,d,e){var g;a=d*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,d,e)};
|
||||
THREE.Matrix4.makeOrtho=function(a,b,d,e,g,j){var l,f,q,c;l=new THREE.Matrix4;f=b-a;q=d-e;c=j-g;a=(b+a)/f;d=(d+e)/q;g=(j+g)/c;l.n11=2/f;l.n12=0;l.n13=0;l.n14=-a;l.n21=0;l.n22=2/q;l.n23=0;l.n24=-d;l.n31=0;l.n32=0;l.n33=-2/c;l.n34=-g;l.n41=0;l.n42=0;l.n43=0;l.n44=1;return l};
|
||||
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.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
|
||||
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],l=b[10]*b[0]-b[2]*b[8],f=-b[6]*b[0]+b[2]*b[4],p=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],t=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*j+b[2]*p;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*e;a.m[2]=b*g;a.m[3]=b*j;a.m[4]=b*l;a.m[5]=b*f;a.m[6]=b*p;a.m[7]=b*c;a.m[8]=b*t;return a};
|
||||
THREE.Matrix4.makeFrustum=function(a,b,d,e,g,j){var l,f,p;l=new THREE.Matrix4;f=2*g/(b-a);p=2*g/(e-d);a=(b+a)/(b-a);d=(e+d)/(e-d);e=-(j+g)/(j-g);g=-2*j*g/(j-g);l.n11=f;l.n12=0;l.n13=a;l.n14=0;l.n21=0;l.n22=p;l.n23=d;l.n24=0;l.n31=0;l.n32=0;l.n33=e;l.n34=g;l.n41=0;l.n42=0;l.n43=-1;l.n44=0;return l};THREE.Matrix4.makePerspective=function(a,b,d,e){var g;a=d*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,d,e)};
|
||||
THREE.Matrix4.makeOrtho=function(a,b,d,e,g,j){var l,f,p,c;l=new THREE.Matrix4;f=b-a;p=d-e;c=j-g;a=(b+a)/f;d=(d+e)/p;g=(j+g)/c;l.n11=2/f;l.n12=0;l.n13=0;l.n14=-a;l.n21=0;l.n22=2/p;l.n23=0;l.n24=-d;l.n31=0;l.n32=0;l.n33=-2/c;l.n34=-g;l.n41=0;l.n42=0;l.n43=0;l.n44=1;return l};
|
||||
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
|
||||
THREE.Face3=function(a,b,d,e,g){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.material=g instanceof Array?g:[g]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
|
||||
THREE.Face4=function(a,b,d,e,g,j){this.a=a;this.b=b;this.c=d;this.d=e;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.material=j instanceof Array?j:[j]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
|
||||
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
|
||||
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={};this.hasTangents=false};
|
||||
THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
|
||||
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,e,g,j,l,f=new THREE.Vector3,q=new THREE.Vector3;e=0;for(g=this.vertices.length;e<g;e++){j=this.vertices[e];j.normal.set(0,0,0)}e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];if(a&&j.vertexNormals.length){f.set(0,0,0);b=0;for(d=j.normal.length;b<d;b++)f.addSelf(j.vertexNormals[b]);f.divideScalar(3)}else{b=this.vertices[j.a];d=this.vertices[j.b];l=this.vertices[j.c];f.sub(l.position,
|
||||
d.position);q.sub(b.position,d.position);f.crossSelf(q)}f.isZero()||f.normalize();j.normal.copy(f)}},computeVertexNormals:function(){var a,b=[],d,e;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){e=this.faces[a];if(e instanceof THREE.Face3){b[e.a].addSelf(e.normal);b[e.b].addSelf(e.normal);b[e.c].addSelf(e.normal)}else if(e instanceof THREE.Face4){b[e.a].addSelf(e.normal);b[e.b].addSelf(e.normal);b[e.c].addSelf(e.normal);b[e.d].addSelf(e.normal)}}a=
|
||||
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=b[e.a].clone();e.vertexNormals[1]=b[e.b].clone();e.vertexNormals[2]=b[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=b[e.a].clone();e.vertexNormals[1]=b[e.b].clone();e.vertexNormals[2]=b[e.c].clone();e.vertexNormals[3]=b[e.d].clone()}}},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;
|
||||
if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(t){var D=[];b=0;for(d=t.length;b<d;b++)t[b]==undefined?D.push("undefined"):D.push(t[b].toString());return D.join("_")}var b,d,e,g,j,l,f,q,c={};e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];l=j.material;f=a(l);if(c[f]==undefined)c[f]={hash:f,counter:0};q=c[f].hash+"_"+c[f].counter;if(this.geometryChunks[q]==
|
||||
undefined)this.geometryChunks[q]={faces:[],material:l,vertices:0};j=j instanceof THREE.Face3?3:4;if(this.geometryChunks[q].vertices+j>65535){c[f].counter+=1;q=c[f].hash+"_"+c[f].counter;if(this.geometryChunks[q]==undefined)this.geometryChunks[q]={faces:[],material:l,vertices:0}}this.geometryChunks[q].faces.push(e);this.geometryChunks[q].vertices+=j}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
|
||||
d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,e,g,j,l,f=new THREE.Vector3,p=new THREE.Vector3;e=0;for(g=this.vertices.length;e<g;e++){j=this.vertices[e];j.normal.set(0,0,0)}e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];if(a&&j.vertexNormals.length){f.set(0,0,0);b=0;for(d=j.normal.length;b<d;b++)f.addSelf(j.vertexNormals[b]);f.divideScalar(3)}else{b=this.vertices[j.a];d=this.vertices[j.b];l=this.vertices[j.c];f.sub(l.position,
|
||||
d.position);p.sub(b.position,d.position);f.crossSelf(p)}f.isZero()||f.normalize();j.normal.copy(f)}},computeVertexNormals:function(){var a,b=[],d,e;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){e=this.faces[a];if(e instanceof THREE.Face3){b[e.a].addSelf(e.normal);b[e.b].addSelf(e.normal);b[e.c].addSelf(e.normal)}else if(e instanceof THREE.Face4){b[e.a].addSelf(e.normal);b[e.b].addSelf(e.normal);b[e.c].addSelf(e.normal);b[e.d].addSelf(e.normal)}}a=
|
||||
0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=b[e.a].clone();e.vertexNormals[1]=b[e.b].clone();e.vertexNormals[2]=b[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=b[e.a].clone();e.vertexNormals[1]=b[e.b].clone();e.vertexNormals[2]=b[e.c].clone();e.vertexNormals[3]=b[e.d].clone()}}},computeTangents:function(){function a(F,O,V,E){j=F.vertices[O].position;l=F.vertices[V].position;
|
||||
f=F.vertices[E].position;p=g[0];c=g[1];t=g[2];C=l.x-j.x;r=f.x-j.x;u=l.y-j.y;v=f.y-j.y;w=l.z-j.z;G=f.z-j.z;H=c.u-p.u;A=t.u-p.u;m=c.v-p.v;h=t.v-p.v;o=1/(H*h-A*m);n.set((h*C-m*r)*o,(h*u-m*v)*o,(h*w-m*G)*o);B.set((H*r-A*C)*o,(H*v-A*u)*o,(H*G-A*w)*o);x[O].addSelf(n);x[V].addSelf(n);x[E].addSelf(n);k[O].addSelf(B);k[V].addSelf(B);k[E].addSelf(B)}var b,d,e,g,j,l,f,p,c,t,C,r,u,v,w,G,H,A,m,h,o,i,x=[],k=[],n=new THREE.Vector3,B=new THREE.Vector3,y=new THREE.Vector3,L=new THREE.Vector3;i=new THREE.Vector3;b=
|
||||
0;for(d=this.vertices.length;b<d;b++){x[b]=new THREE.Vector3;k[b]=new THREE.Vector3}b=0;for(d=this.faces.length;b<d;b++){e=this.faces[b];g=this.uvs[b];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);
|
||||
this.vertices[e.c].normal.copy(e.vertexNormals[2]);this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(d=this.vertices.length;b<d;b++){i.copy(this.vertices[b].normal);e=x[b];y.copy(e);y.subSelf(i.multiplyScalar(i.dot(e))).normalize();L.cross(this.vertices[b].normal,e);test=L.dot(k[b]);e=test<0?-1:1;this.vertices[b].tangent.set(y.x,y.y,y.z,e)}this.hasTangents=true},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
|
||||
y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=
|
||||
vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(t){var C=[];b=0;for(d=t.length;b<d;b++)t[b]==undefined?C.push("undefined"):C.push(t[b].toString());return C.join("_")}var b,d,e,g,j,l,f,p,c={};e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];l=j.material;f=a(l);if(c[f]==undefined)c[f]={hash:f,counter:0};p=c[f].hash+"_"+c[f].counter;if(this.geometryChunks[p]==undefined)this.geometryChunks[p]={faces:[],material:l,
|
||||
vertices:0};j=j instanceof THREE.Face3?3:4;if(this.geometryChunks[p].vertices+j>65535){c[f].counter+=1;p=c[f].hash+"_"+c[f].counter;if(this.geometryChunks[p]==undefined)this.geometryChunks[p]={faces:[],material:l,vertices:0}}this.geometryChunks[p].faces.push(e);this.geometryChunks[p].vertices+=j}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
|
||||
THREE.Camera=function(a,b,d,e){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,e);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
|
||||
THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
|
||||
THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
|
||||
@@ -86,127 +89,132 @@ THREE.Texture=function(a,b,d,e,g,j){this.image=a;this.mapping=b!==undefined?b:ne
|
||||
this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
|
||||
THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
|
||||
THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
|
||||
THREE.Projector=function(){function a(z,m){var h=0,n=1,i=z.z+z.w,y=m.z+m.w,k=-z.z+z.w,o=-m.z+m.w;if(i>=0&&y>=0&&k>=0&&o>=0)return true;else if(i<0&&y<0||k<0&&o<0)return false;else{if(i<0)h=Math.max(h,i/(i-y));else if(y<0)n=Math.min(n,i/(i-y));if(k<0)h=Math.max(h,k/(k-o));else if(o<0)n=Math.min(n,k/(k-o));if(n<h)return false;else{z.lerpSelf(m,h);m.lerpSelf(z,1-n);return true}}}var b=null,d,e,g,j=[],l,f,q=[],c,t,D=[],r=new THREE.Vector4,u=new THREE.Matrix4,v=new THREE.Matrix4,w=new THREE.Vector4,H=
|
||||
new THREE.Vector4,I;this.projectScene=function(z,m){var h,n,i,y,k,o,B,A,P,J,Q,T,E,U,K,L,N;b=[];g=f=t=0;m.autoUpdateMatrix&&m.updateMatrix();u.multiply(m.projectionMatrix,m.matrix);B=z.objects;h=0;for(n=B.length;h<n;h++){A=B[h];A.autoUpdateMatrix&&A.updateMatrix();P=A.matrix;J=A.rotationMatrix;Q=A.material;T=A.overdraw;if(A instanceof THREE.Mesh){E=A.geometry.vertices;i=0;for(y=E.length;i<y;i++){U=E[i];U.positionWorld.copy(U.position);P.multiplyVector3(U.positionWorld);K=U.positionScreen;K.copy(U.positionWorld);
|
||||
u.multiplyVector4(K);K.multiplyScalar(1/K.w);U.__visible=K.z>0&&K.z<1}U=A.geometry.faces;i=0;for(y=U.length;i<y;i++){K=U[i];if(K instanceof THREE.Face3){k=E[K.a];o=E[K.b];L=E[K.c];if(k.__visible&&o.__visible&&L.__visible)if(A.doubleSided||A.flipSided!=(L.positionScreen.x-k.positionScreen.x)*(o.positionScreen.y-k.positionScreen.y)-(L.positionScreen.y-k.positionScreen.y)*(o.positionScreen.x-k.positionScreen.x)<0){d=j[g]=j[g]||new THREE.RenderableFace3;d.v1.positionWorld.copy(k.positionWorld);d.v2.positionWorld.copy(o.positionWorld);
|
||||
d.v3.positionWorld.copy(L.positionWorld);d.v1.positionScreen.copy(k.positionScreen);d.v2.positionScreen.copy(o.positionScreen);d.v3.positionScreen.copy(L.positionScreen);d.normalWorld.copy(K.normal);J.multiplyVector3(d.normalWorld);d.centroidWorld.copy(K.centroid);P.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);u.multiplyVector3(d.centroidScreen);L=K.vertexNormals;I=d.vertexNormalsWorld;k=0;for(o=L.length;k<o;k++){N=I[k]=I[k]||new THREE.Vector3;N.copy(L[k]);J.multiplyVector3(N)}d.z=
|
||||
d.centroidScreen.z;d.meshMaterial=Q;d.faceMaterial=K.material;d.overdraw=T;if(A.geometry.uvs[i]){d.uvs[0]=A.geometry.uvs[i][0];d.uvs[1]=A.geometry.uvs[i][1];d.uvs[2]=A.geometry.uvs[i][2]}b.push(d);g++}}else if(K instanceof THREE.Face4){k=E[K.a];o=E[K.b];L=E[K.c];N=E[K.d];if(k.__visible&&o.__visible&&L.__visible&&N.__visible)if(A.doubleSided||A.flipSided!=((N.positionScreen.x-k.positionScreen.x)*(o.positionScreen.y-k.positionScreen.y)-(N.positionScreen.y-k.positionScreen.y)*(o.positionScreen.x-k.positionScreen.x)<
|
||||
0||(o.positionScreen.x-L.positionScreen.x)*(N.positionScreen.y-L.positionScreen.y)-(o.positionScreen.y-L.positionScreen.y)*(N.positionScreen.x-L.positionScreen.x)<0)){d=j[g]=j[g]||new THREE.RenderableFace3;d.v1.positionWorld.copy(k.positionWorld);d.v2.positionWorld.copy(o.positionWorld);d.v3.positionWorld.copy(N.positionWorld);d.v1.positionScreen.copy(k.positionScreen);d.v2.positionScreen.copy(o.positionScreen);d.v3.positionScreen.copy(N.positionScreen);d.normalWorld.copy(K.normal);J.multiplyVector3(d.normalWorld);
|
||||
d.centroidWorld.copy(K.centroid);P.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);u.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=Q;d.faceMaterial=K.material;d.overdraw=T;if(A.geometry.uvs[i]){d.uvs[0]=A.geometry.uvs[i][0];d.uvs[1]=A.geometry.uvs[i][1];d.uvs[2]=A.geometry.uvs[i][3]}b.push(d);g++;e=j[g]=j[g]||new THREE.RenderableFace3;e.v1.positionWorld.copy(o.positionWorld);e.v2.positionWorld.copy(L.positionWorld);e.v3.positionWorld.copy(N.positionWorld);
|
||||
e.v1.positionScreen.copy(o.positionScreen);e.v2.positionScreen.copy(L.positionScreen);e.v3.positionScreen.copy(N.positionScreen);e.normalWorld.copy(d.normalWorld);e.centroidWorld.copy(d.centroidWorld);e.centroidScreen.copy(d.centroidScreen);e.z=e.centroidScreen.z;e.meshMaterial=Q;e.faceMaterial=K.material;e.overdraw=T;if(A.geometry.uvs[i]){e.uvs[0]=A.geometry.uvs[i][1];e.uvs[1]=A.geometry.uvs[i][2];e.uvs[2]=A.geometry.uvs[i][3]}b.push(e);g++}}}}else if(A instanceof THREE.Line){v.multiply(u,P);E=A.geometry.vertices;
|
||||
U=E[0];U.positionScreen.copy(U.position);v.multiplyVector4(U.positionScreen);i=1;for(y=E.length;i<y;i++){k=E[i];k.positionScreen.copy(k.position);v.multiplyVector4(k.positionScreen);o=E[i-1];w.copy(k.positionScreen);H.copy(o.positionScreen);if(a(w,H)){w.multiplyScalar(1/w.w);H.multiplyScalar(1/H.w);l=q[f]=q[f]||new THREE.RenderableLine;l.v1.positionScreen.copy(w);l.v2.positionScreen.copy(H);l.z=Math.max(w.z,H.z);l.material=A.material;b.push(l);f++}}}else if(A instanceof THREE.Particle){r.set(A.position.x,
|
||||
A.position.y,A.position.z,1);u.multiplyVector4(r);r.z/=r.w;if(r.z>0&&r.z<1){c=D[t]=D[t]||new THREE.RenderableParticle;c.x=r.x/r.w;c.y=r.y/r.w;c.z=r.z;c.rotation=A.rotation.z;c.scale.x=A.scale.x*Math.abs(c.x-(r.x+m.projectionMatrix.n11)/(r.w+m.projectionMatrix.n14));c.scale.y=A.scale.y*Math.abs(c.y-(r.y+m.projectionMatrix.n22)/(r.w+m.projectionMatrix.n24));c.material=A.material;b.push(c);t++}}}b.sort(function(Y,R){return R.z-Y.z});return b};this.unprojectVector=function(z,m){var h=new THREE.Matrix4;
|
||||
h.multiply(THREE.Matrix4.makeInvert(m.matrix),THREE.Matrix4.makeInvert(m.projectionMatrix));h.multiplyVector3(z);return z}};
|
||||
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,e,g,j;this.domElement=document.createElement("div");this.setSize=function(l,f){d=l;e=f;g=d/2;j=e/2};this.render=function(l,f){var q,c,t,D,r,u,v,w;a=b.projectScene(l,f);q=0;for(c=a.length;q<c;q++){r=a[q];if(r instanceof THREE.RenderableParticle){v=r.x*g+g;w=r.y*j+j;t=0;for(D=r.material.length;t<D;t++){u=r.material[t];if(u instanceof THREE.ParticleDOMMaterial){u=u.domElement;u.style.left=v+"px";u.style.top=w+"px"}}}}}};
|
||||
THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),e,g,j,l,f=d.getContext("2d"),q=1,c=0,t=null,D=null,r=1,u=Math.min,v=Math.max,w,H,I,z,m,h,n,i,y,k=new THREE.Color,o=new THREE.Color,B=new THREE.Color,A=new THREE.Color,P=new THREE.Color,J,Q,T,E,U,K,L,N,Y,R,M=new THREE.Rectangle,W=new THREE.Rectangle,p=new THREE.Rectangle,s=false,x=new THREE.Color,G=new THREE.Color,V=new THREE.Color,ba=new THREE.Color,ga=Math.PI*2,$=new THREE.Vector3,ka,pa,Da,da,qa,wa,
|
||||
na=16;ka=document.createElement("canvas");ka.width=ka.height=2;pa=ka.getContext("2d");pa.fillStyle="rgba(0,0,0,1)";pa.fillRect(0,0,2,2);Da=pa.getImageData(0,0,2,2);da=Da.data;qa=document.createElement("canvas");qa.width=qa.height=na;wa=qa.getContext("2d");wa.translate(-na/2,-na/2);wa.scale(na,na);na--;this.domElement=d;this.autoClear=true;this.setSize=function(ia,xa){e=ia;g=xa;j=e/2;l=g/2;d.width=e;d.height=g;M.set(-j,-l,j,l)};this.clear=function(){if(!W.isEmpty()){W.inflate(1);W.minSelf(M);f.clearRect(W.getX(),
|
||||
W.getY(),W.getWidth(),W.getHeight());W.empty()}};this.render=function(ia,xa){function Ma(C){var X,S,F,O=C.lights;G.setRGB(0,0,0);V.setRGB(0,0,0);ba.setRGB(0,0,0);C=0;for(X=O.length;C<X;C++){S=O[C];F=S.color;if(S instanceof THREE.AmbientLight){G.r+=F.r;G.g+=F.g;G.b+=F.b}else if(S instanceof THREE.DirectionalLight){V.r+=F.r;V.g+=F.g;V.b+=F.b}else if(S instanceof THREE.PointLight){ba.r+=F.r;ba.g+=F.g;ba.b+=F.b}}}function ya(C,X,S,F){var O,Z,ca,ea,fa=C.lights;C=0;for(O=fa.length;C<O;C++){Z=fa[C];ca=Z.color;
|
||||
ea=Z.intensity;if(Z instanceof THREE.DirectionalLight){Z=S.dot(Z.position)*ea;if(Z>0){F.r+=ca.r*Z;F.g+=ca.g*Z;F.b+=ca.b*Z}}else if(Z instanceof THREE.PointLight){$.sub(Z.position,X);$.normalize();Z=S.dot($)*ea;if(Z>0){F.r+=ca.r*Z;F.g+=ca.g*Z;F.b+=ca.b*Z}}}}function Na(C,X,S){if(S.opacity!=0){Ea(S.opacity);za(S.blending);var F,O,Z,ca,ea,fa;if(S instanceof THREE.ParticleBasicMaterial){if(S.map){ca=S.map;ea=ca.width>>1;fa=ca.height>>1;O=X.scale.x*j;Z=X.scale.y*l;S=O*ea;F=Z*fa;p.set(C.x-S,C.y-F,C.x+S,
|
||||
C.y+F);if(M.instersects(p)){f.save();f.translate(C.x,C.y);f.rotate(-X.rotation);f.scale(O,-Z);f.translate(-ea,-fa);f.drawImage(ca,0,0);f.restore()}}}else if(S instanceof THREE.ParticleCircleMaterial){if(s){x.r=G.r+V.r+ba.r;x.g=G.g+V.g+ba.g;x.b=G.b+V.b+ba.b;k.r=S.color.r*x.r;k.g=S.color.g*x.g;k.b=S.color.b*x.b;k.updateStyleString()}else k.__styleString=S.color.__styleString;S=X.scale.x*j;F=X.scale.y*l;p.set(C.x-S,C.y-F,C.x+S,C.y+F);if(M.instersects(p)){O=k.__styleString;if(D!=O)f.fillStyle=D=O;f.save();
|
||||
f.translate(C.x,C.y);f.rotate(-X.rotation);f.scale(S,F);f.beginPath();f.arc(0,0,1,0,ga,true);f.closePath();f.fill();f.restore()}}}}function Oa(C,X,S,F){if(F.opacity!=0){Ea(F.opacity);za(F.blending);f.beginPath();f.moveTo(C.positionScreen.x,C.positionScreen.y);f.lineTo(X.positionScreen.x,X.positionScreen.y);f.closePath();if(F instanceof THREE.LineBasicMaterial){k.__styleString=F.color.__styleString;C=F.linewidth;if(r!=C)f.lineWidth=r=C;C=k.__styleString;if(t!=C)f.strokeStyle=t=C;f.stroke();p.inflate(F.linewidth*
|
||||
2)}}}function Ia(C,X,S,F,O,Z){if(O.opacity!=0){Ea(O.opacity);za(O.blending);z=C.positionScreen.x;m=C.positionScreen.y;h=X.positionScreen.x;n=X.positionScreen.y;i=S.positionScreen.x;y=S.positionScreen.y;f.beginPath();f.moveTo(z,m);f.lineTo(h,n);f.lineTo(i,y);f.lineTo(z,m);f.closePath();if(O instanceof THREE.MeshBasicMaterial)if(O.map)O.map.image.loaded&&O.map.mapping instanceof THREE.UVMapping&&ra(z,m,h,n,i,y,O.map.image,F.uvs[0].u,F.uvs[0].v,F.uvs[1].u,F.uvs[1].v,F.uvs[2].u,F.uvs[2].v);else if(O.env_map){if(O.env_map.image.loaded)if(O.env_map.mapping instanceof
|
||||
THREE.SphericalReflectionMapping){C=xa.matrix;$.copy(F.vertexNormalsWorld[0]);U=($.x*C.n11+$.y*C.n12+$.z*C.n13)*0.5+0.5;K=-($.x*C.n21+$.y*C.n22+$.z*C.n23)*0.5+0.5;$.copy(F.vertexNormalsWorld[1]);L=($.x*C.n11+$.y*C.n12+$.z*C.n13)*0.5+0.5;N=-($.x*C.n21+$.y*C.n22+$.z*C.n23)*0.5+0.5;$.copy(F.vertexNormalsWorld[2]);Y=($.x*C.n11+$.y*C.n12+$.z*C.n13)*0.5+0.5;R=-($.x*C.n21+$.y*C.n22+$.z*C.n23)*0.5+0.5;ra(z,m,h,n,i,y,O.env_map.image,U,K,L,N,Y,R)}}else O.wireframe?Aa(O.color.__styleString,O.wireframe_linewidth):
|
||||
Ba(O.color.__styleString);else if(O instanceof THREE.MeshLambertMaterial){if(O.map&&!O.wireframe){O.map.mapping instanceof THREE.UVMapping&&ra(z,m,h,n,i,y,O.map.image,F.uvs[0].u,F.uvs[0].v,F.uvs[1].u,F.uvs[1].v,F.uvs[2].u,F.uvs[2].v);za(THREE.SubtractiveBlending)}if(s)if(!O.wireframe&&O.shading==THREE.SmoothShading&&F.vertexNormalsWorld.length==3){o.r=B.r=A.r=G.r;o.g=B.g=A.g=G.g;o.b=B.b=A.b=G.b;ya(Z,F.v1.positionWorld,F.vertexNormalsWorld[0],o);ya(Z,F.v2.positionWorld,F.vertexNormalsWorld[1],B);ya(Z,
|
||||
F.v3.positionWorld,F.vertexNormalsWorld[2],A);P.r=(B.r+A.r)*0.5;P.g=(B.g+A.g)*0.5;P.b=(B.b+A.b)*0.5;E=Ja(o,B,A,P);ra(z,m,h,n,i,y,E,0,0,1,0,0,1)}else{x.r=G.r;x.g=G.g;x.b=G.b;ya(Z,F.centroidWorld,F.normalWorld,x);k.r=O.color.r*x.r;k.g=O.color.g*x.g;k.b=O.color.b*x.b;k.updateStyleString();O.wireframe?Aa(k.__styleString,O.wireframe_linewidth):Ba(k.__styleString)}else O.wireframe?Aa(O.color.__styleString,O.wireframe_linewidth):Ba(O.color.__styleString)}else if(O instanceof THREE.MeshDepthMaterial){J=O.__2near;
|
||||
Q=O.__farPlusNear;T=O.__farMinusNear;o.r=o.g=o.b=1-J/(Q-C.positionScreen.z*T);B.r=B.g=B.b=1-J/(Q-X.positionScreen.z*T);A.r=A.g=A.b=1-J/(Q-S.positionScreen.z*T);P.r=(B.r+A.r)*0.5;P.g=(B.g+A.g)*0.5;P.b=(B.b+A.b)*0.5;E=Ja(o,B,A,P);ra(z,m,h,n,i,y,E,0,0,1,0,0,1)}else if(O instanceof THREE.MeshNormalMaterial){k.r=Fa(F.normalWorld.x);k.g=Fa(F.normalWorld.y);k.b=Fa(F.normalWorld.z);k.updateStyleString();O.wireframe?Aa(k.__styleString,O.wireframe_linewidth):Ba(k.__styleString)}}}function Aa(C,X){if(t!=C)f.strokeStyle=
|
||||
t=C;if(r!=X)f.lineWidth=r=X;f.stroke();p.inflate(X*2)}function Ba(C){if(D!=C)f.fillStyle=D=C;f.fill()}function ra(C,X,S,F,O,Z,ca,ea,fa,sa,la,ta,ua){var ma,ja;ma=ca.width-1;ja=ca.height-1;ea*=ma;fa*=ja;sa*=ma;la*=ja;ta*=ma;ua*=ja;S-=C;F-=X;O-=C;Z-=X;sa-=ea;la-=fa;ta-=ea;ua-=fa;ja=1/(sa*ua-ta*la);ma=(ua*S-la*O)*ja;la=(ua*F-la*Z)*ja;S=(sa*O-ta*S)*ja;F=(sa*Z-ta*F)*ja;C=C-ma*ea-S*fa;X=X-la*ea-F*fa;f.save();f.transform(ma,la,S,F,C,X);f.clip();f.drawImage(ca,0,0);f.restore()}function Ea(C){if(q!=C)f.globalAlpha=
|
||||
q=C}function za(C){if(c!=C){switch(C){case THREE.NormalBlending:f.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:f.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:f.globalCompositeOperation="darker"}c=C}}function Ja(C,X,S,F){da[0]=v(0,u(255,~~(C.r*255)));da[1]=v(0,u(255,~~(C.g*255)));da[2]=v(0,u(255,~~(C.b*255)));da[4]=v(0,u(255,~~(X.r*255)));da[5]=v(0,u(255,~~(X.g*255)));da[6]=v(0,u(255,~~(X.b*255)));da[8]=v(0,u(255,~~(S.r*255)));da[9]=v(0,u(255,
|
||||
~~(S.g*255)));da[10]=v(0,u(255,~~(S.b*255)));da[12]=v(0,u(255,~~(F.r*255)));da[13]=v(0,u(255,~~(F.g*255)));da[14]=v(0,u(255,~~(F.b*255)));pa.putImageData(Da,0,0);wa.drawImage(ka,0,0);return qa}function Fa(C){return C<0?u((1+C)*0.5,0.5):0.5+u(C*0.5,0.5)}function Ga(C,X){var S=X.x-C.x,F=X.y-C.y,O=1/Math.sqrt(S*S+F*F);S*=O;F*=O;X.x+=S;X.y+=F;C.x-=S;C.y-=F}var Ca,Ka,aa,ha,oa,Ha,La,va;f.setTransform(1,0,0,-1,j,l);this.autoClear&&this.clear();a=b.projectScene(ia,xa);(s=ia.lights.length>0)&&Ma(ia);Ca=0;
|
||||
for(Ka=a.length;Ca<Ka;Ca++){aa=a[Ca];p.empty();if(aa instanceof THREE.RenderableParticle){w=aa;w.x*=j;w.y*=l;ha=0;for(oa=aa.material.length;ha<oa;ha++)Na(w,aa,aa.material[ha],ia)}else if(aa instanceof THREE.RenderableLine){w=aa.v1;H=aa.v2;w.positionScreen.x*=j;w.positionScreen.y*=l;H.positionScreen.x*=j;H.positionScreen.y*=l;p.addPoint(w.positionScreen.x,w.positionScreen.y);p.addPoint(H.positionScreen.x,H.positionScreen.y);if(M.instersects(p)){ha=0;for(oa=aa.material.length;ha<oa;)Oa(w,H,aa,aa.material[ha++],
|
||||
ia)}}else if(aa instanceof THREE.RenderableFace3){w=aa.v1;H=aa.v2;I=aa.v3;w.positionScreen.x*=j;w.positionScreen.y*=l;H.positionScreen.x*=j;H.positionScreen.y*=l;I.positionScreen.x*=j;I.positionScreen.y*=l;if(aa.overdraw){Ga(w.positionScreen,H.positionScreen);Ga(H.positionScreen,I.positionScreen);Ga(I.positionScreen,w.positionScreen)}p.addPoint(w.positionScreen.x,w.positionScreen.y);p.addPoint(H.positionScreen.x,H.positionScreen.y);p.addPoint(I.positionScreen.x,I.positionScreen.y);if(M.instersects(p)){ha=
|
||||
0;for(oa=aa.meshMaterial.length;ha<oa;){va=aa.meshMaterial[ha++];if(va instanceof THREE.MeshFaceMaterial){Ha=0;for(La=aa.faceMaterial.length;Ha<La;)(va=aa.faceMaterial[Ha++])&&Ia(w,H,I,aa,va,ia)}else Ia(w,H,I,aa,va,ia)}}}W.addRectangle(p)}f.setTransform(1,0,0,1,0,0)}};
|
||||
THREE.SVGRenderer=function(){function a(K,L,N){var Y,R,M,W;Y=0;for(R=K.lights.length;Y<R;Y++){M=K.lights[Y];if(M instanceof THREE.DirectionalLight){W=L.normalWorld.dot(M.position)*M.intensity;if(W>0){N.r+=M.color.r*W;N.g+=M.color.g*W;N.b+=M.color.b*W}}else if(M instanceof THREE.PointLight){o.sub(M.position,L.centroidWorld);o.normalize();W=L.normalWorld.dot(o)*M.intensity;if(W>0){N.r+=M.color.r*W;N.g+=M.color.g*W;N.b+=M.color.b*W}}}}function b(K,L,N,Y,R,M){J=e(Q++);J.setAttribute("d","M "+K.positionScreen.x+
|
||||
" "+K.positionScreen.y+" L "+L.positionScreen.x+" "+L.positionScreen.y+" L "+N.positionScreen.x+","+N.positionScreen.y+"z");if(R instanceof THREE.MeshBasicMaterial)m.__styleString=R.color.__styleString;else if(R instanceof THREE.MeshLambertMaterial)if(z){h.r=n.r;h.g=n.g;h.b=n.b;a(M,Y,h);m.r=R.color.r*h.r;m.g=R.color.g*h.g;m.b=R.color.b*h.b;m.updateStyleString()}else m.__styleString=R.color.__styleString;else if(R instanceof THREE.MeshDepthMaterial){k=1-R.__2near/(R.__farPlusNear-Y.z*R.__farMinusNear);
|
||||
m.setRGB(k,k,k)}else R instanceof THREE.MeshNormalMaterial&&m.setRGB(g(Y.normalWorld.x),g(Y.normalWorld.y),g(Y.normalWorld.z));R.wireframe?J.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+R.wireframe_linewidth+"; stroke-opacity: "+R.opacity+"; stroke-linecap: "+R.wireframe_linecap+"; stroke-linejoin: "+R.wireframe_linejoin):J.setAttribute("style","fill: "+m.__styleString+"; fill-opacity: "+R.opacity);f.appendChild(J)}function d(K,L,N,Y,R,M,W){J=e(Q++);J.setAttribute("d",
|
||||
"M "+K.positionScreen.x+" "+K.positionScreen.y+" L "+L.positionScreen.x+" "+L.positionScreen.y+" L "+N.positionScreen.x+","+N.positionScreen.y+" L "+Y.positionScreen.x+","+Y.positionScreen.y+"z");if(M instanceof THREE.MeshBasicMaterial)m.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshLambertMaterial)if(z){h.r=n.r;h.g=n.g;h.b=n.b;a(W,R,h);m.r=M.color.r*h.r;m.g=M.color.g*h.g;m.b=M.color.b*h.b;m.updateStyleString()}else m.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshDepthMaterial){k=
|
||||
1-M.__2near/(M.__farPlusNear-R.z*M.__farMinusNear);m.setRGB(k,k,k)}else M instanceof THREE.MeshNormalMaterial&&m.setRGB(g(R.normalWorld.x),g(R.normalWorld.y),g(R.normalWorld.z));M.wireframe?J.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+M.wireframe_linewidth+"; stroke-opacity: "+M.opacity+"; stroke-linecap: "+M.wireframe_linecap+"; stroke-linejoin: "+M.wireframe_linejoin):J.setAttribute("style","fill: "+m.__styleString+"; fill-opacity: "+M.opacity);f.appendChild(J)}
|
||||
function e(K){if(B[K]==null){B[K]=document.createElementNS("http://www.w3.org/2000/svg","path");U==0&&B[K].setAttribute("shape-rendering","crispEdges");return B[K]}return B[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 j=null,l=new THREE.Projector,f=document.createElementNS("http://www.w3.org/2000/svg","svg"),q,c,t,D,r,u,v,w,H=new THREE.Rectangle,I=new THREE.Rectangle,z=false,m=new THREE.Color(16777215),h=new THREE.Color(16777215),n=new THREE.Color(0),i=new THREE.Color(0),
|
||||
y=new THREE.Color(0),k,o=new THREE.Vector3,B=[],A=[],P=[],J,Q,T,E,U=1;this.domElement=f;this.autoClear=true;this.setQuality=function(K){switch(K){case "high":U=1;break;case "low":U=0}};this.setSize=function(K,L){q=K;c=L;t=q/2;D=c/2;f.setAttribute("viewBox",-t+" "+-D+" "+q+" "+c);f.setAttribute("width",q);f.setAttribute("height",c);H.set(-t,-D,t,D)};this.clear=function(){for(;f.childNodes.length>0;)f.removeChild(f.childNodes[0])};this.render=function(K,L){var N,Y,R,M,W,p,s,x;this.autoClear&&this.clear();
|
||||
j=l.projectScene(K,L);E=T=Q=0;if(z=K.lights.length>0){s=K.lights;n.setRGB(0,0,0);i.setRGB(0,0,0);y.setRGB(0,0,0);N=0;for(Y=s.length;N<Y;N++){R=s[N];M=R.color;if(R instanceof THREE.AmbientLight){n.r+=M.r;n.g+=M.g;n.b+=M.b}else if(R instanceof THREE.DirectionalLight){i.r+=M.r;i.g+=M.g;i.b+=M.b}else if(R instanceof THREE.PointLight){y.r+=M.r;y.g+=M.g;y.b+=M.b}}}N=0;for(Y=j.length;N<Y;N++){s=j[N];I.empty();if(s instanceof THREE.RenderableParticle){r=s;r.x*=t;r.y*=-D;R=0;for(M=s.material.length;R<M;R++)if(x=
|
||||
s.material[R]){W=r;p=s;x=x;var G=T++;if(A[G]==null){A[G]=document.createElementNS("http://www.w3.org/2000/svg","circle");U==0&&A[G].setAttribute("shape-rendering","crispEdges")}J=A[G];J.setAttribute("cx",W.x);J.setAttribute("cy",W.y);J.setAttribute("r",p.scale.x*t);if(x instanceof THREE.ParticleCircleMaterial){if(z){h.r=n.r+i.r+y.r;h.g=n.g+i.g+y.g;h.b=n.b+i.b+y.b;m.r=x.color.r*h.r;m.g=x.color.g*h.g;m.b=x.color.b*h.b;m.updateStyleString()}else m=x.color;J.setAttribute("style","fill: "+m.__styleString)}f.appendChild(J)}}else if(s instanceof
|
||||
THREE.RenderableLine){r=s.v1;u=s.v2;r.positionScreen.x*=t;r.positionScreen.y*=-D;u.positionScreen.x*=t;u.positionScreen.y*=-D;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);if(H.instersects(I)){R=0;for(M=s.material.length;R<M;)if(x=s.material[R++]){W=r;p=u;x=x;G=E++;if(P[G]==null){P[G]=document.createElementNS("http://www.w3.org/2000/svg","line");U==0&&P[G].setAttribute("shape-rendering","crispEdges")}J=P[G];J.setAttribute("x1",W.positionScreen.x);
|
||||
J.setAttribute("y1",W.positionScreen.y);J.setAttribute("x2",p.positionScreen.x);J.setAttribute("y2",p.positionScreen.y);if(x instanceof THREE.LineBasicMaterial){m.__styleString=x.color.__styleString;J.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+x.linewidth+"; stroke-opacity: "+x.opacity+"; stroke-linecap: "+x.linecap+"; stroke-linejoin: "+x.linejoin);f.appendChild(J)}}}}else if(s instanceof THREE.RenderableFace3){r=s.v1;u=s.v2;v=s.v3;r.positionScreen.x*=t;r.positionScreen.y*=
|
||||
-D;u.positionScreen.x*=t;u.positionScreen.y*=-D;v.positionScreen.x*=t;v.positionScreen.y*=-D;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);I.addPoint(v.positionScreen.x,v.positionScreen.y);if(H.instersects(I)){R=0;for(M=s.meshMaterial.length;R<M;){x=s.meshMaterial[R++];if(x instanceof THREE.MeshFaceMaterial){W=0;for(p=s.faceMaterial.length;W<p;)(x=s.faceMaterial[W++])&&b(r,u,v,s,x,K)}else x&&b(r,u,v,s,x,K)}}}else if(s instanceof THREE.RenderableFace4){r=
|
||||
s.v1;u=s.v2;v=s.v3;w=s.v4;r.positionScreen.x*=t;r.positionScreen.y*=-D;u.positionScreen.x*=t;u.positionScreen.y*=-D;v.positionScreen.x*=t;v.positionScreen.y*=-D;w.positionScreen.x*=t;w.positionScreen.y*=-D;I.addPoint(r.positionScreen.x,r.positionScreen.y);I.addPoint(u.positionScreen.x,u.positionScreen.y);I.addPoint(v.positionScreen.x,v.positionScreen.y);I.addPoint(w.positionScreen.x,w.positionScreen.y);if(H.instersects(I)){R=0;for(M=s.meshMaterial.length;R<M;){x=s.meshMaterial[R++];if(x instanceof
|
||||
THREE.MeshFaceMaterial){W=0;for(p=s.faceMaterial.length;W<p;)(x=s.faceMaterial[W++])&&d(r,u,v,w,s,x,K)}else x&&d(r,u,v,w,s,x,K)}}}}}};
|
||||
THREE.WebGLRenderer=function(a){function b(h,n){var i=c.createProgram();c.attachShader(i,l("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+h));c.attachShader(i,l("vertex","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"+n));c.linkProgram(i);c.getProgramParameter(i,
|
||||
c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(i,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");i.uniforms={};i.attributes={};return i}function d(h,n){if(h.image.length==6){if(!h.image.__webGLTextureCube&&!h.image.__cubeMapInitialized&&h.image.loadCount==6){h.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,h.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 i=0;i<6;++i)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+i,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image[i]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);h.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+n);c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube)}}function e(h,
|
||||
n){if(!h.__webGLTexture&&h.image.loaded){h.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,h.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,f(h.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,f(h.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,f(h.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,f(h.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+
|
||||
n);c.bindTexture(c.TEXTURE_2D,h.__webGLTexture)}function g(h,n){var i,y,k;i=0;for(y=n.length;i<y;i++){k=n[i];h.uniforms[k]=c.getUniformLocation(h,k)}}function j(h,n){var i,y,k;i=0;for(y=n.length;i<y;i++){k=n[i];h.attributes[k]=c.getAttribLocation(h,k);h.attributes[k]>=0&&c.enableVertexAttribArray(h.attributes[k])}}function l(h,n){var i;if(h=="fragment")i=c.createShader(c.FRAGMENT_SHADER);else if(h=="vertex")i=c.createShader(c.VERTEX_SHADER);c.shaderSource(i,n);c.compileShader(i);if(!c.getShaderParameter(i,
|
||||
c.COMPILE_STATUS)){alert(c.getShaderInfoLog(i));return null}return i}function f(h){switch(h){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 q=document.createElement("canvas"),c,t,D,r=new THREE.Matrix4,u,v=new Float32Array(16),w=new Float32Array(16),H=new Float32Array(16),I=new Float32Array(9),z=new Float32Array(16);a=function(h,n){if(h){var i,y,k,o=pointLights=maxDirLights=maxPointLights=0;i=0;for(y=h.lights.length;i<y;i++){k=h.lights[i];k instanceof THREE.DirectionalLight&&o++;k instanceof THREE.PointLight&&pointLights++}if(pointLights+o<=n){maxDirLights=
|
||||
o;maxPointLights=pointLights}else{maxDirLights=Math.ceil(n*o/(pointLights+o));maxPointLights=n-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:n-1}}(a,4);this.domElement=q;this.autoClear=true;try{c=q.getContext("experimental-webgl",{antialias:true})}catch(m){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);
|
||||
c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);t=D=function(h,n){var i=[h?"#define MAX_DIR_LIGHTS "+h:"",n?"#define MAX_POINT_LIGHTS "+n:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",h?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",n?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":
|
||||
"",n?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",n?"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;",
|
||||
h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",h?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",h?"}":"",n?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",n?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",n?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
||||
"",n?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",n?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",n?"}":"","}\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"),
|
||||
y=[h?"#define MAX_DIR_LIGHTS "+h:"",n?"#define MAX_POINT_LIGHTS "+n:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
||||
h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",n?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
|
||||
n?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",n?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",n?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",n?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",n?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",n?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",n?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",n?"float pointSpecularWeight = 0.0;":"",n?"if ( pointDotNormalHalf >= 0.0 )":
|
||||
"",n?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",n?"pointDiffuse += mColor * pointDiffuseWeight;":"",n?"pointSpecular += mSpecular * pointSpecularWeight;":"",n?"}":"",h?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"vec3 dirVector = normalize( lDirection.xyz );":"",h?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
|
||||
"",h?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",h?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",h?"float dirSpecularWeight = 0.0;":"",h?"if ( dirDotNormalHalf >= 0.0 )":"",h?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",h?"dirDiffuse += mColor * dirDiffuseWeight;":"",h?"dirSpecular += mSpecular * dirSpecularWeight;":"",h?"}":"","vec4 totalLight = mAmbient;",h?"totalLight += dirDiffuse + dirSpecular;":"",n?"totalLight += pointDiffuse + pointSpecular;":
|
||||
THREE.Projector=function(){function a(A,m){var h=0,o=1,i=A.z+A.w,x=m.z+m.w,k=-A.z+A.w,n=-m.z+m.w;if(i>=0&&x>=0&&k>=0&&n>=0)return true;else if(i<0&&x<0||k<0&&n<0)return false;else{if(i<0)h=Math.max(h,i/(i-x));else if(x<0)o=Math.min(o,i/(i-x));if(k<0)h=Math.max(h,k/(k-n));else if(n<0)o=Math.min(o,k/(k-n));if(o<h)return false;else{A.lerpSelf(m,h);m.lerpSelf(A,1-o);return true}}}var b=null,d,e,g,j=[],l,f,p=[],c,t,C=[],r=new THREE.Vector4,u=new THREE.Matrix4,v=new THREE.Matrix4,w=new THREE.Vector4,G=
|
||||
new THREE.Vector4,H;this.projectScene=function(A,m){var h,o,i,x,k,n,B,y,L,F,O,V,E,S,N,T,U;b=[];g=f=t=0;m.autoUpdateMatrix&&m.updateMatrix();u.multiply(m.projectionMatrix,m.matrix);B=A.objects;h=0;for(o=B.length;h<o;h++){y=B[h];y.autoUpdateMatrix&&y.updateMatrix();L=y.matrix;F=y.rotationMatrix;O=y.material;V=y.overdraw;if(y instanceof THREE.Mesh){E=y.geometry.vertices;i=0;for(x=E.length;i<x;i++){S=E[i];S.positionWorld.copy(S.position);L.multiplyVector3(S.positionWorld);N=S.positionScreen;N.copy(S.positionWorld);
|
||||
u.multiplyVector4(N);N.multiplyScalar(1/N.w);S.__visible=N.z>0&&N.z<1}S=y.geometry.faces;i=0;for(x=S.length;i<x;i++){N=S[i];if(N instanceof THREE.Face3){k=E[N.a];n=E[N.b];T=E[N.c];if(k.__visible&&n.__visible&&T.__visible)if(y.doubleSided||y.flipSided!=(T.positionScreen.x-k.positionScreen.x)*(n.positionScreen.y-k.positionScreen.y)-(T.positionScreen.y-k.positionScreen.y)*(n.positionScreen.x-k.positionScreen.x)<0){d=j[g]=j[g]||new THREE.RenderableFace3;d.v1.positionWorld.copy(k.positionWorld);d.v2.positionWorld.copy(n.positionWorld);
|
||||
d.v3.positionWorld.copy(T.positionWorld);d.v1.positionScreen.copy(k.positionScreen);d.v2.positionScreen.copy(n.positionScreen);d.v3.positionScreen.copy(T.positionScreen);d.normalWorld.copy(N.normal);F.multiplyVector3(d.normalWorld);d.centroidWorld.copy(N.centroid);L.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);u.multiplyVector3(d.centroidScreen);T=N.vertexNormals;H=d.vertexNormalsWorld;k=0;for(n=T.length;k<n;k++){U=H[k]=H[k]||new THREE.Vector3;U.copy(T[k]);F.multiplyVector3(U)}d.z=
|
||||
d.centroidScreen.z;d.meshMaterial=O;d.faceMaterial=N.material;d.overdraw=V;if(y.geometry.uvs[i]){d.uvs[0]=y.geometry.uvs[i][0];d.uvs[1]=y.geometry.uvs[i][1];d.uvs[2]=y.geometry.uvs[i][2]}b.push(d);g++}}else if(N instanceof THREE.Face4){k=E[N.a];n=E[N.b];T=E[N.c];U=E[N.d];if(k.__visible&&n.__visible&&T.__visible&&U.__visible)if(y.doubleSided||y.flipSided!=((U.positionScreen.x-k.positionScreen.x)*(n.positionScreen.y-k.positionScreen.y)-(U.positionScreen.y-k.positionScreen.y)*(n.positionScreen.x-k.positionScreen.x)<
|
||||
0||(n.positionScreen.x-T.positionScreen.x)*(U.positionScreen.y-T.positionScreen.y)-(n.positionScreen.y-T.positionScreen.y)*(U.positionScreen.x-T.positionScreen.x)<0)){d=j[g]=j[g]||new THREE.RenderableFace3;d.v1.positionWorld.copy(k.positionWorld);d.v2.positionWorld.copy(n.positionWorld);d.v3.positionWorld.copy(U.positionWorld);d.v1.positionScreen.copy(k.positionScreen);d.v2.positionScreen.copy(n.positionScreen);d.v3.positionScreen.copy(U.positionScreen);d.normalWorld.copy(N.normal);F.multiplyVector3(d.normalWorld);
|
||||
d.centroidWorld.copy(N.centroid);L.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);u.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=O;d.faceMaterial=N.material;d.overdraw=V;if(y.geometry.uvs[i]){d.uvs[0]=y.geometry.uvs[i][0];d.uvs[1]=y.geometry.uvs[i][1];d.uvs[2]=y.geometry.uvs[i][3]}b.push(d);g++;e=j[g]=j[g]||new THREE.RenderableFace3;e.v1.positionWorld.copy(n.positionWorld);e.v2.positionWorld.copy(T.positionWorld);e.v3.positionWorld.copy(U.positionWorld);
|
||||
e.v1.positionScreen.copy(n.positionScreen);e.v2.positionScreen.copy(T.positionScreen);e.v3.positionScreen.copy(U.positionScreen);e.normalWorld.copy(d.normalWorld);e.centroidWorld.copy(d.centroidWorld);e.centroidScreen.copy(d.centroidScreen);e.z=e.centroidScreen.z;e.meshMaterial=O;e.faceMaterial=N.material;e.overdraw=V;if(y.geometry.uvs[i]){e.uvs[0]=y.geometry.uvs[i][1];e.uvs[1]=y.geometry.uvs[i][2];e.uvs[2]=y.geometry.uvs[i][3]}b.push(e);g++}}}}else if(y instanceof THREE.Line){v.multiply(u,L);E=y.geometry.vertices;
|
||||
S=E[0];S.positionScreen.copy(S.position);v.multiplyVector4(S.positionScreen);i=1;for(x=E.length;i<x;i++){k=E[i];k.positionScreen.copy(k.position);v.multiplyVector4(k.positionScreen);n=E[i-1];w.copy(k.positionScreen);G.copy(n.positionScreen);if(a(w,G)){w.multiplyScalar(1/w.w);G.multiplyScalar(1/G.w);l=p[f]=p[f]||new THREE.RenderableLine;l.v1.positionScreen.copy(w);l.v2.positionScreen.copy(G);l.z=Math.max(w.z,G.z);l.material=y.material;b.push(l);f++}}}else if(y instanceof THREE.Particle){r.set(y.position.x,
|
||||
y.position.y,y.position.z,1);u.multiplyVector4(r);r.z/=r.w;if(r.z>0&&r.z<1){c=C[t]=C[t]||new THREE.RenderableParticle;c.x=r.x/r.w;c.y=r.y/r.w;c.z=r.z;c.rotation=y.rotation.z;c.scale.x=y.scale.x*Math.abs(c.x-(r.x+m.projectionMatrix.n11)/(r.w+m.projectionMatrix.n14));c.scale.y=y.scale.y*Math.abs(c.y-(r.y+m.projectionMatrix.n22)/(r.w+m.projectionMatrix.n24));c.material=y.material;b.push(c);t++}}}b.sort(function(Q,K){return K.z-Q.z});return b};this.unprojectVector=function(A,m){var h=new THREE.Matrix4;
|
||||
h.multiply(THREE.Matrix4.makeInvert(m.matrix),THREE.Matrix4.makeInvert(m.projectionMatrix));h.multiplyVector3(A);return A}};
|
||||
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,e,g,j;this.domElement=document.createElement("div");this.setSize=function(l,f){d=l;e=f;g=d/2;j=e/2};this.render=function(l,f){var p,c,t,C,r,u,v,w;a=b.projectScene(l,f);p=0;for(c=a.length;p<c;p++){r=a[p];if(r instanceof THREE.RenderableParticle){v=r.x*g+g;w=r.y*j+j;t=0;for(C=r.material.length;t<C;t++){u=r.material[t];if(u instanceof THREE.ParticleDOMMaterial){u=u.domElement;u.style.left=v+"px";u.style.top=w+"px"}}}}}};
|
||||
THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),e,g,j,l,f=d.getContext("2d"),p=1,c=0,t=null,C=null,r=1,u=Math.min,v=Math.max,w,G,H,A,m,h,o,i,x,k=new THREE.Color,n=new THREE.Color,B=new THREE.Color,y=new THREE.Color,L=new THREE.Color,F,O,V,E,S,N,T,U,Q,K,M=new THREE.Rectangle,X=new THREE.Rectangle,q=new THREE.Rectangle,s=false,z=new THREE.Color,J=new THREE.Color,W=new THREE.Color,ba=new THREE.Color,ga=Math.PI*2,$=new THREE.Vector3,ka,pa,Da,da,qa,wa,
|
||||
na=16;ka=document.createElement("canvas");ka.width=ka.height=2;pa=ka.getContext("2d");pa.fillStyle="rgba(0,0,0,1)";pa.fillRect(0,0,2,2);Da=pa.getImageData(0,0,2,2);da=Da.data;qa=document.createElement("canvas");qa.width=qa.height=na;wa=qa.getContext("2d");wa.translate(-na/2,-na/2);wa.scale(na,na);na--;this.domElement=d;this.autoClear=true;this.setSize=function(ia,xa){e=ia;g=xa;j=e/2;l=g/2;d.width=e;d.height=g;M.set(-j,-l,j,l)};this.clear=function(){if(!X.isEmpty()){X.inflate(1);X.minSelf(M);f.clearRect(X.getX(),
|
||||
X.getY(),X.getWidth(),X.getHeight());X.empty()}};this.render=function(ia,xa){function Ma(D){var Y,R,I,P=D.lights;J.setRGB(0,0,0);W.setRGB(0,0,0);ba.setRGB(0,0,0);D=0;for(Y=P.length;D<Y;D++){R=P[D];I=R.color;if(R instanceof THREE.AmbientLight){J.r+=I.r;J.g+=I.g;J.b+=I.b}else if(R instanceof THREE.DirectionalLight){W.r+=I.r;W.g+=I.g;W.b+=I.b}else if(R instanceof THREE.PointLight){ba.r+=I.r;ba.g+=I.g;ba.b+=I.b}}}function ya(D,Y,R,I){var P,Z,ca,ea,fa=D.lights;D=0;for(P=fa.length;D<P;D++){Z=fa[D];ca=Z.color;
|
||||
ea=Z.intensity;if(Z instanceof THREE.DirectionalLight){Z=R.dot(Z.position)*ea;if(Z>0){I.r+=ca.r*Z;I.g+=ca.g*Z;I.b+=ca.b*Z}}else if(Z instanceof THREE.PointLight){$.sub(Z.position,Y);$.normalize();Z=R.dot($)*ea;if(Z>0){I.r+=ca.r*Z;I.g+=ca.g*Z;I.b+=ca.b*Z}}}}function Na(D,Y,R){if(R.opacity!=0){Ea(R.opacity);za(R.blending);var I,P,Z,ca,ea,fa;if(R instanceof THREE.ParticleBasicMaterial){if(R.map){ca=R.map;ea=ca.width>>1;fa=ca.height>>1;P=Y.scale.x*j;Z=Y.scale.y*l;R=P*ea;I=Z*fa;q.set(D.x-R,D.y-I,D.x+R,
|
||||
D.y+I);if(M.instersects(q)){f.save();f.translate(D.x,D.y);f.rotate(-Y.rotation);f.scale(P,-Z);f.translate(-ea,-fa);f.drawImage(ca,0,0);f.restore()}}}else if(R instanceof THREE.ParticleCircleMaterial){if(s){z.r=J.r+W.r+ba.r;z.g=J.g+W.g+ba.g;z.b=J.b+W.b+ba.b;k.r=R.color.r*z.r;k.g=R.color.g*z.g;k.b=R.color.b*z.b;k.updateStyleString()}else k.__styleString=R.color.__styleString;R=Y.scale.x*j;I=Y.scale.y*l;q.set(D.x-R,D.y-I,D.x+R,D.y+I);if(M.instersects(q)){P=k.__styleString;if(C!=P)f.fillStyle=C=P;f.save();
|
||||
f.translate(D.x,D.y);f.rotate(-Y.rotation);f.scale(R,I);f.beginPath();f.arc(0,0,1,0,ga,true);f.closePath();f.fill();f.restore()}}}}function Oa(D,Y,R,I){if(I.opacity!=0){Ea(I.opacity);za(I.blending);f.beginPath();f.moveTo(D.positionScreen.x,D.positionScreen.y);f.lineTo(Y.positionScreen.x,Y.positionScreen.y);f.closePath();if(I instanceof THREE.LineBasicMaterial){k.__styleString=I.color.__styleString;D=I.linewidth;if(r!=D)f.lineWidth=r=D;D=k.__styleString;if(t!=D)f.strokeStyle=t=D;f.stroke();q.inflate(I.linewidth*
|
||||
2)}}}function Ia(D,Y,R,I,P,Z){if(P.opacity!=0){Ea(P.opacity);za(P.blending);A=D.positionScreen.x;m=D.positionScreen.y;h=Y.positionScreen.x;o=Y.positionScreen.y;i=R.positionScreen.x;x=R.positionScreen.y;f.beginPath();f.moveTo(A,m);f.lineTo(h,o);f.lineTo(i,x);f.lineTo(A,m);f.closePath();if(P instanceof THREE.MeshBasicMaterial)if(P.map)P.map.image.loaded&&P.map.mapping instanceof THREE.UVMapping&&ra(A,m,h,o,i,x,P.map.image,I.uvs[0].u,I.uvs[0].v,I.uvs[1].u,I.uvs[1].v,I.uvs[2].u,I.uvs[2].v);else if(P.env_map){if(P.env_map.image.loaded)if(P.env_map.mapping instanceof
|
||||
THREE.SphericalReflectionMapping){D=xa.matrix;$.copy(I.vertexNormalsWorld[0]);S=($.x*D.n11+$.y*D.n12+$.z*D.n13)*0.5+0.5;N=-($.x*D.n21+$.y*D.n22+$.z*D.n23)*0.5+0.5;$.copy(I.vertexNormalsWorld[1]);T=($.x*D.n11+$.y*D.n12+$.z*D.n13)*0.5+0.5;U=-($.x*D.n21+$.y*D.n22+$.z*D.n23)*0.5+0.5;$.copy(I.vertexNormalsWorld[2]);Q=($.x*D.n11+$.y*D.n12+$.z*D.n13)*0.5+0.5;K=-($.x*D.n21+$.y*D.n22+$.z*D.n23)*0.5+0.5;ra(A,m,h,o,i,x,P.env_map.image,S,N,T,U,Q,K)}}else P.wireframe?Aa(P.color.__styleString,P.wireframe_linewidth):
|
||||
Ba(P.color.__styleString);else if(P instanceof THREE.MeshLambertMaterial){if(P.map&&!P.wireframe){P.map.mapping instanceof THREE.UVMapping&&ra(A,m,h,o,i,x,P.map.image,I.uvs[0].u,I.uvs[0].v,I.uvs[1].u,I.uvs[1].v,I.uvs[2].u,I.uvs[2].v);za(THREE.SubtractiveBlending)}if(s)if(!P.wireframe&&P.shading==THREE.SmoothShading&&I.vertexNormalsWorld.length==3){n.r=B.r=y.r=J.r;n.g=B.g=y.g=J.g;n.b=B.b=y.b=J.b;ya(Z,I.v1.positionWorld,I.vertexNormalsWorld[0],n);ya(Z,I.v2.positionWorld,I.vertexNormalsWorld[1],B);ya(Z,
|
||||
I.v3.positionWorld,I.vertexNormalsWorld[2],y);L.r=(B.r+y.r)*0.5;L.g=(B.g+y.g)*0.5;L.b=(B.b+y.b)*0.5;E=Ja(n,B,y,L);ra(A,m,h,o,i,x,E,0,0,1,0,0,1)}else{z.r=J.r;z.g=J.g;z.b=J.b;ya(Z,I.centroidWorld,I.normalWorld,z);k.r=P.color.r*z.r;k.g=P.color.g*z.g;k.b=P.color.b*z.b;k.updateStyleString();P.wireframe?Aa(k.__styleString,P.wireframe_linewidth):Ba(k.__styleString)}else P.wireframe?Aa(P.color.__styleString,P.wireframe_linewidth):Ba(P.color.__styleString)}else if(P instanceof THREE.MeshDepthMaterial){F=P.__2near;
|
||||
O=P.__farPlusNear;V=P.__farMinusNear;n.r=n.g=n.b=1-F/(O-D.positionScreen.z*V);B.r=B.g=B.b=1-F/(O-Y.positionScreen.z*V);y.r=y.g=y.b=1-F/(O-R.positionScreen.z*V);L.r=(B.r+y.r)*0.5;L.g=(B.g+y.g)*0.5;L.b=(B.b+y.b)*0.5;E=Ja(n,B,y,L);ra(A,m,h,o,i,x,E,0,0,1,0,0,1)}else if(P instanceof THREE.MeshNormalMaterial){k.r=Fa(I.normalWorld.x);k.g=Fa(I.normalWorld.y);k.b=Fa(I.normalWorld.z);k.updateStyleString();P.wireframe?Aa(k.__styleString,P.wireframe_linewidth):Ba(k.__styleString)}}}function Aa(D,Y){if(t!=D)f.strokeStyle=
|
||||
t=D;if(r!=Y)f.lineWidth=r=Y;f.stroke();q.inflate(Y*2)}function Ba(D){if(C!=D)f.fillStyle=C=D;f.fill()}function ra(D,Y,R,I,P,Z,ca,ea,fa,sa,la,ta,ua){var ma,ja;ma=ca.width-1;ja=ca.height-1;ea*=ma;fa*=ja;sa*=ma;la*=ja;ta*=ma;ua*=ja;R-=D;I-=Y;P-=D;Z-=Y;sa-=ea;la-=fa;ta-=ea;ua-=fa;ja=1/(sa*ua-ta*la);ma=(ua*R-la*P)*ja;la=(ua*I-la*Z)*ja;R=(sa*P-ta*R)*ja;I=(sa*Z-ta*I)*ja;D=D-ma*ea-R*fa;Y=Y-la*ea-I*fa;f.save();f.transform(ma,la,R,I,D,Y);f.clip();f.drawImage(ca,0,0);f.restore()}function Ea(D){if(p!=D)f.globalAlpha=
|
||||
p=D}function za(D){if(c!=D){switch(D){case THREE.NormalBlending:f.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:f.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:f.globalCompositeOperation="darker"}c=D}}function Ja(D,Y,R,I){da[0]=v(0,u(255,~~(D.r*255)));da[1]=v(0,u(255,~~(D.g*255)));da[2]=v(0,u(255,~~(D.b*255)));da[4]=v(0,u(255,~~(Y.r*255)));da[5]=v(0,u(255,~~(Y.g*255)));da[6]=v(0,u(255,~~(Y.b*255)));da[8]=v(0,u(255,~~(R.r*255)));da[9]=v(0,u(255,
|
||||
~~(R.g*255)));da[10]=v(0,u(255,~~(R.b*255)));da[12]=v(0,u(255,~~(I.r*255)));da[13]=v(0,u(255,~~(I.g*255)));da[14]=v(0,u(255,~~(I.b*255)));pa.putImageData(Da,0,0);wa.drawImage(ka,0,0);return qa}function Fa(D){return D<0?u((1+D)*0.5,0.5):0.5+u(D*0.5,0.5)}function Ga(D,Y){var R=Y.x-D.x,I=Y.y-D.y,P=1/Math.sqrt(R*R+I*I);R*=P;I*=P;Y.x+=R;Y.y+=I;D.x-=R;D.y-=I}var Ca,Ka,aa,ha,oa,Ha,La,va;f.setTransform(1,0,0,-1,j,l);this.autoClear&&this.clear();a=b.projectScene(ia,xa);(s=ia.lights.length>0)&&Ma(ia);Ca=0;
|
||||
for(Ka=a.length;Ca<Ka;Ca++){aa=a[Ca];q.empty();if(aa instanceof THREE.RenderableParticle){w=aa;w.x*=j;w.y*=l;ha=0;for(oa=aa.material.length;ha<oa;ha++)Na(w,aa,aa.material[ha],ia)}else if(aa instanceof THREE.RenderableLine){w=aa.v1;G=aa.v2;w.positionScreen.x*=j;w.positionScreen.y*=l;G.positionScreen.x*=j;G.positionScreen.y*=l;q.addPoint(w.positionScreen.x,w.positionScreen.y);q.addPoint(G.positionScreen.x,G.positionScreen.y);if(M.instersects(q)){ha=0;for(oa=aa.material.length;ha<oa;)Oa(w,G,aa,aa.material[ha++],
|
||||
ia)}}else if(aa instanceof THREE.RenderableFace3){w=aa.v1;G=aa.v2;H=aa.v3;w.positionScreen.x*=j;w.positionScreen.y*=l;G.positionScreen.x*=j;G.positionScreen.y*=l;H.positionScreen.x*=j;H.positionScreen.y*=l;if(aa.overdraw){Ga(w.positionScreen,G.positionScreen);Ga(G.positionScreen,H.positionScreen);Ga(H.positionScreen,w.positionScreen)}q.addPoint(w.positionScreen.x,w.positionScreen.y);q.addPoint(G.positionScreen.x,G.positionScreen.y);q.addPoint(H.positionScreen.x,H.positionScreen.y);if(M.instersects(q)){ha=
|
||||
0;for(oa=aa.meshMaterial.length;ha<oa;){va=aa.meshMaterial[ha++];if(va instanceof THREE.MeshFaceMaterial){Ha=0;for(La=aa.faceMaterial.length;Ha<La;)(va=aa.faceMaterial[Ha++])&&Ia(w,G,H,aa,va,ia)}else Ia(w,G,H,aa,va,ia)}}}X.addRectangle(q)}f.setTransform(1,0,0,1,0,0)}};
|
||||
THREE.SVGRenderer=function(){function a(N,T,U){var Q,K,M,X;Q=0;for(K=N.lights.length;Q<K;Q++){M=N.lights[Q];if(M instanceof THREE.DirectionalLight){X=T.normalWorld.dot(M.position)*M.intensity;if(X>0){U.r+=M.color.r*X;U.g+=M.color.g*X;U.b+=M.color.b*X}}else if(M instanceof THREE.PointLight){n.sub(M.position,T.centroidWorld);n.normalize();X=T.normalWorld.dot(n)*M.intensity;if(X>0){U.r+=M.color.r*X;U.g+=M.color.g*X;U.b+=M.color.b*X}}}}function b(N,T,U,Q,K,M){F=e(O++);F.setAttribute("d","M "+N.positionScreen.x+
|
||||
" "+N.positionScreen.y+" L "+T.positionScreen.x+" "+T.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+"z");if(K instanceof THREE.MeshBasicMaterial)m.__styleString=K.color.__styleString;else if(K instanceof THREE.MeshLambertMaterial)if(A){h.r=o.r;h.g=o.g;h.b=o.b;a(M,Q,h);m.r=K.color.r*h.r;m.g=K.color.g*h.g;m.b=K.color.b*h.b;m.updateStyleString()}else m.__styleString=K.color.__styleString;else if(K instanceof THREE.MeshDepthMaterial){k=1-K.__2near/(K.__farPlusNear-Q.z*K.__farMinusNear);
|
||||
m.setRGB(k,k,k)}else K instanceof THREE.MeshNormalMaterial&&m.setRGB(g(Q.normalWorld.x),g(Q.normalWorld.y),g(Q.normalWorld.z));K.wireframe?F.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+K.wireframe_linewidth+"; stroke-opacity: "+K.opacity+"; stroke-linecap: "+K.wireframe_linecap+"; stroke-linejoin: "+K.wireframe_linejoin):F.setAttribute("style","fill: "+m.__styleString+"; fill-opacity: "+K.opacity);f.appendChild(F)}function d(N,T,U,Q,K,M,X){F=e(O++);F.setAttribute("d",
|
||||
"M "+N.positionScreen.x+" "+N.positionScreen.y+" L "+T.positionScreen.x+" "+T.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(M instanceof THREE.MeshBasicMaterial)m.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshLambertMaterial)if(A){h.r=o.r;h.g=o.g;h.b=o.b;a(X,K,h);m.r=M.color.r*h.r;m.g=M.color.g*h.g;m.b=M.color.b*h.b;m.updateStyleString()}else m.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshDepthMaterial){k=
|
||||
1-M.__2near/(M.__farPlusNear-K.z*M.__farMinusNear);m.setRGB(k,k,k)}else M instanceof THREE.MeshNormalMaterial&&m.setRGB(g(K.normalWorld.x),g(K.normalWorld.y),g(K.normalWorld.z));M.wireframe?F.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+M.wireframe_linewidth+"; stroke-opacity: "+M.opacity+"; stroke-linecap: "+M.wireframe_linecap+"; stroke-linejoin: "+M.wireframe_linejoin):F.setAttribute("style","fill: "+m.__styleString+"; fill-opacity: "+M.opacity);f.appendChild(F)}
|
||||
function e(N){if(B[N]==null){B[N]=document.createElementNS("http://www.w3.org/2000/svg","path");S==0&&B[N].setAttribute("shape-rendering","crispEdges");return B[N]}return B[N]}function g(N){return N<0?Math.min((1+N)*0.5,0.5):0.5+Math.min(N*0.5,0.5)}var j=null,l=new THREE.Projector,f=document.createElementNS("http://www.w3.org/2000/svg","svg"),p,c,t,C,r,u,v,w,G=new THREE.Rectangle,H=new THREE.Rectangle,A=false,m=new THREE.Color(16777215),h=new THREE.Color(16777215),o=new THREE.Color(0),i=new THREE.Color(0),
|
||||
x=new THREE.Color(0),k,n=new THREE.Vector3,B=[],y=[],L=[],F,O,V,E,S=1;this.domElement=f;this.autoClear=true;this.setQuality=function(N){switch(N){case "high":S=1;break;case "low":S=0}};this.setSize=function(N,T){p=N;c=T;t=p/2;C=c/2;f.setAttribute("viewBox",-t+" "+-C+" "+p+" "+c);f.setAttribute("width",p);f.setAttribute("height",c);G.set(-t,-C,t,C)};this.clear=function(){for(;f.childNodes.length>0;)f.removeChild(f.childNodes[0])};this.render=function(N,T){var U,Q,K,M,X,q,s,z;this.autoClear&&this.clear();
|
||||
j=l.projectScene(N,T);E=V=O=0;if(A=N.lights.length>0){s=N.lights;o.setRGB(0,0,0);i.setRGB(0,0,0);x.setRGB(0,0,0);U=0;for(Q=s.length;U<Q;U++){K=s[U];M=K.color;if(K instanceof THREE.AmbientLight){o.r+=M.r;o.g+=M.g;o.b+=M.b}else if(K instanceof THREE.DirectionalLight){i.r+=M.r;i.g+=M.g;i.b+=M.b}else if(K instanceof THREE.PointLight){x.r+=M.r;x.g+=M.g;x.b+=M.b}}}U=0;for(Q=j.length;U<Q;U++){s=j[U];H.empty();if(s instanceof THREE.RenderableParticle){r=s;r.x*=t;r.y*=-C;K=0;for(M=s.material.length;K<M;K++)if(z=
|
||||
s.material[K]){X=r;q=s;z=z;var J=V++;if(y[J]==null){y[J]=document.createElementNS("http://www.w3.org/2000/svg","circle");S==0&&y[J].setAttribute("shape-rendering","crispEdges")}F=y[J];F.setAttribute("cx",X.x);F.setAttribute("cy",X.y);F.setAttribute("r",q.scale.x*t);if(z instanceof THREE.ParticleCircleMaterial){if(A){h.r=o.r+i.r+x.r;h.g=o.g+i.g+x.g;h.b=o.b+i.b+x.b;m.r=z.color.r*h.r;m.g=z.color.g*h.g;m.b=z.color.b*h.b;m.updateStyleString()}else m=z.color;F.setAttribute("style","fill: "+m.__styleString)}f.appendChild(F)}}else if(s instanceof
|
||||
THREE.RenderableLine){r=s.v1;u=s.v2;r.positionScreen.x*=t;r.positionScreen.y*=-C;u.positionScreen.x*=t;u.positionScreen.y*=-C;H.addPoint(r.positionScreen.x,r.positionScreen.y);H.addPoint(u.positionScreen.x,u.positionScreen.y);if(G.instersects(H)){K=0;for(M=s.material.length;K<M;)if(z=s.material[K++]){X=r;q=u;z=z;J=E++;if(L[J]==null){L[J]=document.createElementNS("http://www.w3.org/2000/svg","line");S==0&&L[J].setAttribute("shape-rendering","crispEdges")}F=L[J];F.setAttribute("x1",X.positionScreen.x);
|
||||
F.setAttribute("y1",X.positionScreen.y);F.setAttribute("x2",q.positionScreen.x);F.setAttribute("y2",q.positionScreen.y);if(z instanceof THREE.LineBasicMaterial){m.__styleString=z.color.__styleString;F.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+z.linewidth+"; stroke-opacity: "+z.opacity+"; stroke-linecap: "+z.linecap+"; stroke-linejoin: "+z.linejoin);f.appendChild(F)}}}}else if(s instanceof THREE.RenderableFace3){r=s.v1;u=s.v2;v=s.v3;r.positionScreen.x*=t;r.positionScreen.y*=
|
||||
-C;u.positionScreen.x*=t;u.positionScreen.y*=-C;v.positionScreen.x*=t;v.positionScreen.y*=-C;H.addPoint(r.positionScreen.x,r.positionScreen.y);H.addPoint(u.positionScreen.x,u.positionScreen.y);H.addPoint(v.positionScreen.x,v.positionScreen.y);if(G.instersects(H)){K=0;for(M=s.meshMaterial.length;K<M;){z=s.meshMaterial[K++];if(z instanceof THREE.MeshFaceMaterial){X=0;for(q=s.faceMaterial.length;X<q;)(z=s.faceMaterial[X++])&&b(r,u,v,s,z,N)}else z&&b(r,u,v,s,z,N)}}}else if(s instanceof THREE.RenderableFace4){r=
|
||||
s.v1;u=s.v2;v=s.v3;w=s.v4;r.positionScreen.x*=t;r.positionScreen.y*=-C;u.positionScreen.x*=t;u.positionScreen.y*=-C;v.positionScreen.x*=t;v.positionScreen.y*=-C;w.positionScreen.x*=t;w.positionScreen.y*=-C;H.addPoint(r.positionScreen.x,r.positionScreen.y);H.addPoint(u.positionScreen.x,u.positionScreen.y);H.addPoint(v.positionScreen.x,v.positionScreen.y);H.addPoint(w.positionScreen.x,w.positionScreen.y);if(G.instersects(H)){K=0;for(M=s.meshMaterial.length;K<M;){z=s.meshMaterial[K++];if(z instanceof
|
||||
THREE.MeshFaceMaterial){X=0;for(q=s.faceMaterial.length;X<q;)(z=s.faceMaterial[X++])&&d(r,u,v,w,s,z,N)}else z&&d(r,u,v,w,s,z,N)}}}}}};
|
||||
THREE.WebGLRenderer=function(a){function b(h,o){var i=c.createProgram(),x=[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(i,l("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+
|
||||
h));c.attachShader(i,l("vertex",x+o));c.linkProgram(i);c.getProgramParameter(i,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(i,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");i.uniforms={};i.attributes={};return i}function d(h,o){if(h.image.length==6){if(!h.image.__webGLTextureCube&&!h.image.__cubeMapInitialized&&h.image.loadCount==6){h.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,h.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 i=0;i<6;++i)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+i,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image[i]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);h.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+o);c.bindTexture(c.TEXTURE_CUBE_MAP,
|
||||
h.image.__webGLTextureCube)}}function e(h,o){if(!h.__webGLTexture&&h.image.loaded){h.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,h.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,f(h.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,f(h.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,f(h.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,f(h.min_filter));c.generateMipmap(c.TEXTURE_2D);
|
||||
c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+o);c.bindTexture(c.TEXTURE_2D,h.__webGLTexture)}function g(h,o){var i,x,k;i=0;for(x=o.length;i<x;i++){k=o[i];h.uniforms[k]=c.getUniformLocation(h,k)}}function j(h,o){var i,x,k;i=0;for(x=o.length;i<x;i++){k=o[i];h.attributes[k]=c.getAttribLocation(h,k);h.attributes[k]>=0&&c.enableVertexAttribArray(h.attributes[k])}}function l(h,o){var i;if(h=="fragment")i=c.createShader(c.FRAGMENT_SHADER);else if(h=="vertex")i=c.createShader(c.VERTEX_SHADER);
|
||||
c.shaderSource(i,o);c.compileShader(i);if(!c.getShaderParameter(i,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(i));return null}return i}function f(h){switch(h){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 p=document.createElement("canvas"),c,t,C,r=new THREE.Matrix4,u,v=new Float32Array(16),w=new Float32Array(16),G=new Float32Array(16),H=new Float32Array(9),A=new Float32Array(16);a=function(h,o){if(h){var i,x,k,n=pointLights=maxDirLights=maxPointLights=0;i=0;for(x=h.lights.length;i<x;i++){k=h.lights[i];k instanceof THREE.DirectionalLight&&n++;k instanceof
|
||||
THREE.PointLight&&pointLights++}if(pointLights+n<=o){maxDirLights=n;maxPointLights=pointLights}else{maxDirLights=Math.ceil(o*n/(pointLights+n));maxPointLights=o-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:o-1}}(a,4);this.domElement=p;this.autoClear=true;try{c=p.getContext("experimental-webgl",{antialias:true})}catch(m){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);
|
||||
c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);t=C=function(h,o){var i=[h?"#define MAX_DIR_LIGHTS "+h:"",o?"#define MAX_POINT_LIGHTS "+o:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",h?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":
|
||||
"",o?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",o?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",o?"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;",
|
||||
h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",h?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",h?"}":"",o?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",o?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",o?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
||||
"",o?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",o?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",o?"}":"","}\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"),
|
||||
x=[h?"#define MAX_DIR_LIGHTS "+h:"",o?"#define MAX_POINT_LIGHTS "+o:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
||||
h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",o?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
|
||||
o?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",o?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",o?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",o?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",o?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",o?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",o?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",o?"float pointSpecularWeight = 0.0;":"",o?"if ( pointDotNormalHalf >= 0.0 )":
|
||||
"",o?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",o?"pointDiffuse += mColor * pointDiffuseWeight;":"",o?"pointSpecular += mSpecular * pointSpecularWeight;":"",o?"}":"",h?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"vec3 dirVector = normalize( lDirection.xyz );":"",h?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
|
||||
"",h?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",h?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",h?"float dirSpecularWeight = 0.0;":"",h?"if ( dirDotNormalHalf >= 0.0 )":"",h?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",h?"dirDiffuse += mColor * dirDiffuseWeight;":"",h?"dirSpecular += mSpecular * dirSpecularWeight;":"",h?"}":"","vec4 totalLight = mAmbient;",h?"totalLight += dirDiffuse + dirSpecular;":"",o?"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}"].join("\n");
|
||||
i=b(y,i);c.useProgram(i);g(i,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);h&&g(i,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);n&&g(i,["pointLightNumber","pointLightColor",
|
||||
"pointLightPosition"]);c.uniform1i(i.uniforms.enableMap,0);c.uniform1i(i.uniforms.tMap,0);c.uniform1i(i.uniforms.enableCubeMap,0);c.uniform1i(i.uniforms.tCube,1);c.uniform1i(i.uniforms.mixEnvMap,0);c.uniform1i(i.uniforms.useRefract,0);j(i,["position","normal","uv"]);return i}(a.directional,a.point);this.setSize=function(h,n){q.width=h;q.height=n;c.viewport(0,0,q.width,q.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(h,n){var i,y,k,o,B,A=[],
|
||||
P=[],J=[];o=[];B=[];c.uniform1i(h.uniforms.enableLighting,n.length);i=0;for(y=n.length;i<y;i++){k=n[i];if(k instanceof THREE.AmbientLight)A.push(k);else if(k instanceof THREE.DirectionalLight)J.push(k);else k instanceof THREE.PointLight&&P.push(k)}i=k=o=B=0;for(y=A.length;i<y;i++){k+=A[i].color.r;o+=A[i].color.g;B+=A[i].color.b}c.uniform3f(h.uniforms.ambientLightColor,k,o,B);o=[];B=[];i=0;for(y=J.length;i<y;i++){k=J[i];o.push(k.color.r*k.intensity);o.push(k.color.g*k.intensity);o.push(k.color.b*k.intensity);
|
||||
B.push(k.position.x);B.push(k.position.y);B.push(k.position.z)}if(J.length){c.uniform1i(h.uniforms.directionalLightNumber,J.length);c.uniform3fv(h.uniforms.directionalLightDirection,B);c.uniform3fv(h.uniforms.directionalLightColor,o)}o=[];B=[];i=0;for(y=P.length;i<y;i++){k=P[i];o.push(k.color.r*k.intensity);o.push(k.color.g*k.intensity);o.push(k.color.b*k.intensity);B.push(k.position.x);B.push(k.position.y);B.push(k.position.z)}if(P.length){c.uniform1i(h.uniforms.pointLightNumber,P.length);c.uniform3fv(h.uniforms.pointLightPosition,
|
||||
B);c.uniform3fv(h.uniforms.pointLightColor,o)}};this.createBuffers=function(h,n){var i,y,k,o,B,A,P,J,Q=[],T=[],E=[],U=[],K=[],L=0,N=h.geometry.geometryChunks[n],Y;k=false;i=0;for(y=h.material.length;i<y;i++){meshMaterial=h.material[i];if(meshMaterial instanceof THREE.MeshFaceMaterial){B=0;for(Y=N.material.length;B<Y;B++)if(N.material[B]&&N.material[B].shading!=undefined&&N.material[B].shading==THREE.SmoothShading){k=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
|
||||
THREE.SmoothShading){k=true;break}if(k)break}Y=k;i=0;for(y=N.faces.length;i<y;i++){k=N.faces[i];o=h.geometry.faces[k];B=o.vertexNormals;faceNormal=o.normal;k=h.geometry.uvs[k];if(o instanceof THREE.Face3){A=h.geometry.vertices[o.a].position;P=h.geometry.vertices[o.b].position;J=h.geometry.vertices[o.c].position;E.push(A.x,A.y,A.z);E.push(P.x,P.y,P.z);E.push(J.x,J.y,J.z);if(B.length==3&&Y)for(o=0;o<3;o++)U.push(B[o].x,B[o].y,B[o].z);else for(o=0;o<3;o++)U.push(faceNormal.x,faceNormal.y,faceNormal.z);
|
||||
if(k)for(o=0;o<3;o++)K.push(k[o].u,k[o].v);Q.push(L,L+1,L+2);T.push(L,L+1);T.push(L,L+2);T.push(L+1,L+2);L+=3}else if(o instanceof THREE.Face4){A=h.geometry.vertices[o.a].position;P=h.geometry.vertices[o.b].position;J=h.geometry.vertices[o.c].position;o=h.geometry.vertices[o.d].position;E.push(A.x,A.y,A.z);E.push(P.x,P.y,P.z);E.push(J.x,J.y,J.z);E.push(o.x,o.y,o.z);if(B.length==4&&Y)for(o=0;o<4;o++)U.push(B[o].x,B[o].y,B[o].z);else for(o=0;o<4;o++)U.push(faceNormal.x,faceNormal.y,faceNormal.z);if(k)for(o=
|
||||
0;o<4;o++)K.push(k[o].u,k[o].v);Q.push(L,L+1,L+2);Q.push(L,L+2,L+3);T.push(L,L+1);T.push(L,L+2);T.push(L,L+3);T.push(L+1,L+2);T.push(L+2,L+3);L+=4}}if(E.length){N.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,N.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(E),c.STATIC_DRAW);N.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,N.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(U),c.STATIC_DRAW);if(K.length>0){N.__webGLUVBuffer=c.createBuffer();
|
||||
c.bindBuffer(c.ARRAY_BUFFER,N.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(K),c.STATIC_DRAW)}N.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,N.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);N.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,N.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(T),c.STATIC_DRAW);N.__webGLFaceCount=Q.length;N.__webGLLineCount=T.length}};this.renderBuffer=
|
||||
function(h,n,i,y){var k,o,B,A,P,J,Q,T,E;if(i instanceof THREE.MeshShaderMaterial){if(!i.program){i.program=b(i.fragment_shader,i.vertex_shader);Q=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(E in i.uniforms)Q.push(E);g(i.program,Q);j(i.program,["position","normal","uv"])}E=i.program}else E=D;if(E!=t){c.useProgram(E);t=E}E==D&&this.setupLights(E,n);this.loadCamera(E,h);this.loadMatrices(E);if(i instanceof THREE.MeshShaderMaterial){B=i.wireframe;
|
||||
A=i.wireframe_linewidth;h=E;n=i.uniforms;var U;for(k in n){T=n[k].type;Q=n[k].value;U=h.uniforms[k];if(T=="i")c.uniform1i(U,Q);else if(T=="f")c.uniform1f(U,Q);else if(T=="v3")c.uniform3f(U,Q.x,Q.y,Q.z);else if(T=="c")c.uniform3f(U,Q.r,Q.g,Q.b);else if(T=="t"){c.uniform1i(U,Q);if(T=n[k].texture)T.image instanceof Array&&T.image.length==6?d(T,Q):e(T,Q)}}}if(i instanceof THREE.MeshPhongMaterial||i instanceof THREE.MeshLambertMaterial||i instanceof THREE.MeshBasicMaterial){k=i.color;o=i.opacity;B=i.wireframe;
|
||||
A=i.wireframe_linewidth;P=i.map;J=i.env_map;n=i.combine==THREE.MixOperation;h=i.reflectivity;T=i.env_map&&i.env_map.mapping instanceof THREE.CubeRefractionMapping;Q=i.refraction_ratio;c.uniform4f(E.uniforms.mColor,k.r*o,k.g*o,k.b*o,o);c.uniform1i(E.uniforms.mixEnvMap,n);c.uniform1f(E.uniforms.mReflectivity,h);c.uniform1i(E.uniforms.useRefract,T);c.uniform1f(E.uniforms.mRefractionRatio,Q)}if(i instanceof THREE.MeshNormalMaterial){o=i.opacity;c.uniform1f(E.uniforms.mOpacity,o);c.uniform1i(E.uniforms.material,
|
||||
4)}else if(i instanceof THREE.MeshDepthMaterial){o=i.opacity;B=i.wireframe;A=i.wireframe_linewidth;c.uniform1f(E.uniforms.mOpacity,o);c.uniform1f(E.uniforms.m2Near,i.__2near);c.uniform1f(E.uniforms.mFarPlusNear,i.__farPlusNear);c.uniform1f(E.uniforms.mFarMinusNear,i.__farMinusNear);c.uniform1i(E.uniforms.material,3)}else if(i instanceof THREE.MeshPhongMaterial){k=i.ambient;h=i.specular;i=i.shininess;c.uniform4f(E.uniforms.mAmbient,k.r,k.g,k.b,o);c.uniform4f(E.uniforms.mSpecular,h.r,h.g,h.b,o);c.uniform1f(E.uniforms.mShininess,
|
||||
i);c.uniform1i(E.uniforms.material,2)}else if(i instanceof THREE.MeshLambertMaterial)c.uniform1i(E.uniforms.material,1);else if(i instanceof THREE.MeshBasicMaterial)c.uniform1i(E.uniforms.material,0);else if(i instanceof THREE.MeshCubeMaterial){c.uniform1i(E.uniforms.material,5);J=i.env_map}if(P){e(P,0);c.uniform1i(E.uniforms.tMap,0);c.uniform1i(E.uniforms.enableMap,1)}else c.uniform1i(E.uniforms.enableMap,0);if(J){d(J,1);c.uniform1i(E.uniforms.tCube,1);c.uniform1i(E.uniforms.enableCubeMap,1)}else c.uniform1i(E.uniforms.enableCubeMap,
|
||||
0);o=E.attributes;c.bindBuffer(c.ARRAY_BUFFER,y.__webGLVertexBuffer);c.vertexAttribPointer(o.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,y.__webGLNormalBuffer);c.vertexAttribPointer(o.normal,3,c.FLOAT,false,0,0);if(o.uv>=0)if(y.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,y.__webGLUVBuffer);c.enableVertexAttribArray(o.uv);c.vertexAttribPointer(o.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(o.uv);if(B){c.lineWidth(A);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLLineBuffer);
|
||||
c.drawElements(c.LINES,y.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,y.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(h,n,i,y,k,o){var B,A,P,J,Q;P=0;for(J=i.material.length;P<J;P++){B=i.material[P];if(B instanceof THREE.MeshFaceMaterial){B=0;for(A=y.material.length;B<A;B++)if((Q=y.material[B])&&Q.blending==k&&Q.opacity<1==o){this.setBlending(Q.blending);this.renderBuffer(h,n,Q,y)}}else if((Q=B)&&Q.blending==
|
||||
k&&Q.opacity<1==o){this.setBlending(Q.blending);this.renderBuffer(h,n,Q,y)}}};this.render=function(h,n){var i,y,k,o,B=h.lights;this.initWebGLObjects(h);this.autoClear&&this.clear();n.autoUpdateMatrix&&n.updateMatrix();i=0;for(y=h.__webGLObjects.length;i<y;i++){k=h.__webGLObjects[i];o=k.object;k=k.buffer;if(o.visible){this.setupMatrices(o,n);this.renderPass(n,B,o,k,THREE.NormalBlending,false)}}i=0;for(y=h.__webGLObjects.length;i<y;i++){k=h.__webGLObjects[i];o=k.object;k=k.buffer;if(o.visible){this.setupMatrices(o,
|
||||
n);this.renderPass(n,B,o,k,THREE.AdditiveBlending,false);this.renderPass(n,B,o,k,THREE.SubtractiveBlending,false);this.renderPass(n,B,o,k,THREE.AdditiveBlending,true);this.renderPass(n,B,o,k,THREE.SubtractiveBlending,true);this.renderPass(n,B,o,k,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(h){var n,i,y,k,o,B;if(!h.__webGLObjects){h.__webGLObjects=[];h.__webGLObjectsMap={}}n=0;for(i=h.objects.length;n<i;n++){y=h.objects[n];if(h.__webGLObjectsMap[y.id]==undefined)h.__webGLObjectsMap[y.id]=
|
||||
{};B=h.__webGLObjectsMap[y.id];if(y instanceof THREE.Mesh)for(o in y.geometry.geometryChunks){k=y.geometry.geometryChunks[o];k.__webGLVertexBuffer||this.createBuffers(y,o);if(B[o]==undefined){k={buffer:k,object:y};h.__webGLObjects.push(k);B[o]=1}}}};this.removeObject=function(h,n){var i,y;for(i=h.__webGLObjects.length-1;i>=0;i--){y=h.__webGLObjects[i].object;n==y&&h.__webGLObjects.splice(i,1)}};this.setupMatrices=function(h,n){h.autoUpdateMatrix&&h.updateMatrix();r.multiply(n.matrix,h.matrix);v.set(n.matrix.flatten());
|
||||
w.set(r.flatten());H.set(n.projectionMatrix.flatten());u=THREE.Matrix4.makeInvert3x3(r).transpose();I.set(u.m);z.set(h.matrix.flatten())};this.loadMatrices=function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,v);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,w);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,H);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,I);c.uniformMatrix4fv(h.uniforms.objectMatrix,false,z)};this.loadCamera=function(h,n){c.uniform3f(h.uniforms.cameraPosition,
|
||||
n.position.x,n.position.y,n.position.z)};this.setBlending=function(h){switch(h){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(h,n){if(h){!n||n=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(h=="back")c.cullFace(c.BACK);else h=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);
|
||||
c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};
|
||||
THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
|
||||
var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,g=d?b.geometry:b,j=a.vertices,l=g.vertices,f=a.faces,q=g.faces,c=a.uvs;g=g.uvs;d&&b.updateMatrix();for(var t=0,D=l.length;t<D;t++){var r=new THREE.Vertex(l[t].position.clone());d&&b.matrix.multiplyVector3(r.position);j.push(r)}t=0;for(D=q.length;t<D;t++){l=q[t];var u,v=l.vertexNormals;if(l instanceof THREE.Face3)u=new THREE.Face3(l.a+e,l.b+e,l.c+e);else if(l instanceof THREE.Face4)u=new THREE.Face4(l.a+e,l.b+
|
||||
e,l.c+e,l.d+e);u.centroid.copy(l.centroid);u.normal.copy(l.normal);d=0;for(j=v.length;d<j;d++){r=v[d];u.vertexNormals.push(r.clone())}u.material=l.material.slice();f.push(u)}t=0;for(D=g.length;t<D;t++){e=g[t];f=[];d=0;for(j=e.length;d<j;d++)f.push(new THREE.UV(e[d].u,e[d].v));c.push(f)}}},ImageUtils={loadTexture:function(a,b){var d=new Image;d.onload=function(){this.loaded=true};d.src=a;return new THREE.Texture(d,b)},loadArray:function(a){var b,d,e=[];b=e.loadCount=0;for(d=a.length;b<d;++b){e[b]=
|
||||
new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=true};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,d,e,g,j,l,f,q,c){b=new THREE.Mesh(b,c);b.scale.x=b.scale.y=b.scale.z=d;b.position.x=e;b.position.y=g;b.position.z=j;b.rotation.x=l;b.rotation.y=f;b.rotation.z=q;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,d){d=new THREE.MeshCubeMaterial({env_map:d});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),d);a.addObject(b);return b},addPanoramaCube:function(a,
|
||||
i=b(x,i);c.useProgram(i);g(i,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);h&&g(i,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);o&&g(i,["pointLightNumber","pointLightColor",
|
||||
"pointLightPosition"]);c.uniform1i(i.uniforms.enableMap,0);c.uniform1i(i.uniforms.tMap,0);c.uniform1i(i.uniforms.enableCubeMap,0);c.uniform1i(i.uniforms.tCube,1);c.uniform1i(i.uniforms.mixEnvMap,0);c.uniform1i(i.uniforms.useRefract,0);j(i,["position","normal","uv"]);return i}(a.directional,a.point);this.setSize=function(h,o){p.width=h;p.height=o;c.viewport(0,0,p.width,p.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(h,o){var i,x,k,n,B,y=[],
|
||||
L=[],F=[];n=[];B=[];c.uniform1i(h.uniforms.enableLighting,o.length);i=0;for(x=o.length;i<x;i++){k=o[i];if(k instanceof THREE.AmbientLight)y.push(k);else if(k instanceof THREE.DirectionalLight)F.push(k);else k instanceof THREE.PointLight&&L.push(k)}i=k=n=B=0;for(x=y.length;i<x;i++){k+=y[i].color.r;n+=y[i].color.g;B+=y[i].color.b}c.uniform3f(h.uniforms.ambientLightColor,k,n,B);n=[];B=[];i=0;for(x=F.length;i<x;i++){k=F[i];n.push(k.color.r*k.intensity);n.push(k.color.g*k.intensity);n.push(k.color.b*k.intensity);
|
||||
B.push(k.position.x);B.push(k.position.y);B.push(k.position.z)}if(F.length){c.uniform1i(h.uniforms.directionalLightNumber,F.length);c.uniform3fv(h.uniforms.directionalLightDirection,B);c.uniform3fv(h.uniforms.directionalLightColor,n)}n=[];B=[];i=0;for(x=L.length;i<x;i++){k=L[i];n.push(k.color.r*k.intensity);n.push(k.color.g*k.intensity);n.push(k.color.b*k.intensity);B.push(k.position.x);B.push(k.position.y);B.push(k.position.z)}if(L.length){c.uniform1i(h.uniforms.pointLightNumber,L.length);c.uniform3fv(h.uniforms.pointLightPosition,
|
||||
B);c.uniform3fv(h.uniforms.pointLightColor,n)}};this.createBuffers=function(h,o){var i,x,k,n,B,y,L,F,O,V=[],E=[],S=[],N=[],T=[],U=[],Q=0,K=h.geometry.geometryChunks[o],M;k=false;i=0;for(x=h.material.length;i<x;i++){meshMaterial=h.material[i];if(meshMaterial instanceof THREE.MeshFaceMaterial){B=0;for(M=K.material.length;B<M;B++)if(K.material[B]&&K.material[B].shading!=undefined&&K.material[B].shading==THREE.SmoothShading){k=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
|
||||
THREE.SmoothShading){k=true;break}if(k)break}M=k;i=0;for(x=K.faces.length;i<x;i++){k=K.faces[i];n=h.geometry.faces[k];B=n.vertexNormals;faceNormal=n.normal;k=h.geometry.uvs[k];if(n instanceof THREE.Face3){y=h.geometry.vertices[n.a].position;L=h.geometry.vertices[n.b].position;F=h.geometry.vertices[n.c].position;S.push(y.x,y.y,y.z);S.push(L.x,L.y,L.z);S.push(F.x,F.y,F.z);if(h.geometry.hasTangents){y=h.geometry.vertices[n.a].tangent;L=h.geometry.vertices[n.b].tangent;F=h.geometry.vertices[n.c].tangent;
|
||||
T.push(y.x,y.y,y.z,y.w);T.push(L.x,L.y,L.z,L.w);T.push(F.x,F.y,F.z,F.w)}if(B.length==3&&M)for(n=0;n<3;n++)N.push(B[n].x,B[n].y,B[n].z);else for(n=0;n<3;n++)N.push(faceNormal.x,faceNormal.y,faceNormal.z);if(k)for(n=0;n<3;n++)U.push(k[n].u,k[n].v);V.push(Q,Q+1,Q+2);E.push(Q,Q+1);E.push(Q,Q+2);E.push(Q+1,Q+2);Q+=3}else if(n instanceof THREE.Face4){y=h.geometry.vertices[n.a].position;L=h.geometry.vertices[n.b].position;F=h.geometry.vertices[n.c].position;O=h.geometry.vertices[n.d].position;S.push(y.x,
|
||||
y.y,y.z);S.push(L.x,L.y,L.z);S.push(F.x,F.y,F.z);S.push(O.x,O.y,O.z);if(h.geometry.hasTangents){y=h.geometry.vertices[n.a].tangent;L=h.geometry.vertices[n.b].tangent;F=h.geometry.vertices[n.c].tangent;n=h.geometry.vertices[n.d].tangent;T.push(y.x,y.y,y.z,y.w);T.push(L.x,L.y,L.z,L.w);T.push(F.x,F.y,F.z,F.w);T.push(n.x,n.y,n.z,n.w)}if(B.length==4&&M)for(n=0;n<4;n++)N.push(B[n].x,B[n].y,B[n].z);else for(n=0;n<4;n++)N.push(faceNormal.x,faceNormal.y,faceNormal.z);if(k)for(n=0;n<4;n++)U.push(k[n].u,k[n].v);
|
||||
V.push(Q,Q+1,Q+2);V.push(Q,Q+2,Q+3);E.push(Q,Q+1);E.push(Q,Q+2);E.push(Q,Q+3);E.push(Q+1,Q+2);E.push(Q+2,Q+3);Q+=4}}if(S.length){K.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,K.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(S),c.STATIC_DRAW);K.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,K.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(N),c.STATIC_DRAW);if(h.geometry.hasTangents){K.__webGLTangentBuffer=c.createBuffer();
|
||||
c.bindBuffer(c.ARRAY_BUFFER,K.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(T),c.STATIC_DRAW)}if(U.length>0){K.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,K.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(U),c.STATIC_DRAW)}K.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,K.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(V),c.STATIC_DRAW);K.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
|
||||
K.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(E),c.STATIC_DRAW);K.__webGLFaceCount=V.length;K.__webGLLineCount=E.length}};this.renderBuffer=function(h,o,i,x){var k,n,B,y,L,F,O,V,E;if(i instanceof THREE.MeshShaderMaterial){if(!i.program){i.program=b(i.fragment_shader,i.vertex_shader);O=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(E in i.uniforms)O.push(E);g(i.program,O);j(i.program,["position","normal","uv","tangent"])}E=
|
||||
i.program}else E=C;if(E!=t){c.useProgram(E);t=E}E==C&&this.setupLights(E,o);this.loadCamera(E,h);this.loadMatrices(E);if(i instanceof THREE.MeshShaderMaterial){B=i.wireframe;y=i.wireframe_linewidth;h=E;o=i.uniforms;var S;for(k in o){V=o[k].type;O=o[k].value;S=h.uniforms[k];if(V=="i")c.uniform1i(S,O);else if(V=="f")c.uniform1f(S,O);else if(V=="v3")c.uniform3f(S,O.x,O.y,O.z);else if(V=="c")c.uniform3f(S,O.r,O.g,O.b);else if(V=="t"){c.uniform1i(S,O);if(V=o[k].texture)V.image instanceof Array&&V.image.length==
|
||||
6?d(V,O):e(V,O)}}}if(i instanceof THREE.MeshPhongMaterial||i instanceof THREE.MeshLambertMaterial||i instanceof THREE.MeshBasicMaterial){k=i.color;n=i.opacity;B=i.wireframe;y=i.wireframe_linewidth;L=i.map;F=i.env_map;o=i.combine==THREE.MixOperation;h=i.reflectivity;V=i.env_map&&i.env_map.mapping instanceof THREE.CubeRefractionMapping;O=i.refraction_ratio;c.uniform4f(E.uniforms.mColor,k.r*n,k.g*n,k.b*n,n);c.uniform1i(E.uniforms.mixEnvMap,o);c.uniform1f(E.uniforms.mReflectivity,h);c.uniform1i(E.uniforms.useRefract,
|
||||
V);c.uniform1f(E.uniforms.mRefractionRatio,O)}if(i instanceof THREE.MeshNormalMaterial){n=i.opacity;c.uniform1f(E.uniforms.mOpacity,n);c.uniform1i(E.uniforms.material,4)}else if(i instanceof THREE.MeshDepthMaterial){n=i.opacity;B=i.wireframe;y=i.wireframe_linewidth;c.uniform1f(E.uniforms.mOpacity,n);c.uniform1f(E.uniforms.m2Near,i.__2near);c.uniform1f(E.uniforms.mFarPlusNear,i.__farPlusNear);c.uniform1f(E.uniforms.mFarMinusNear,i.__farMinusNear);c.uniform1i(E.uniforms.material,3)}else if(i instanceof
|
||||
THREE.MeshPhongMaterial){k=i.ambient;h=i.specular;i=i.shininess;c.uniform4f(E.uniforms.mAmbient,k.r,k.g,k.b,n);c.uniform4f(E.uniforms.mSpecular,h.r,h.g,h.b,n);c.uniform1f(E.uniforms.mShininess,i);c.uniform1i(E.uniforms.material,2)}else if(i instanceof THREE.MeshLambertMaterial)c.uniform1i(E.uniforms.material,1);else if(i instanceof THREE.MeshBasicMaterial)c.uniform1i(E.uniforms.material,0);else if(i instanceof THREE.MeshCubeMaterial){c.uniform1i(E.uniforms.material,5);F=i.env_map}if(L){e(L,0);c.uniform1i(E.uniforms.tMap,
|
||||
0);c.uniform1i(E.uniforms.enableMap,1)}else c.uniform1i(E.uniforms.enableMap,0);if(F){d(F,1);c.uniform1i(E.uniforms.tCube,1);c.uniform1i(E.uniforms.enableCubeMap,1)}else c.uniform1i(E.uniforms.enableCubeMap,0);n=E.attributes;c.bindBuffer(c.ARRAY_BUFFER,x.__webGLVertexBuffer);c.vertexAttribPointer(n.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,x.__webGLNormalBuffer);c.vertexAttribPointer(n.normal,3,c.FLOAT,false,0,0);if(n.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,x.__webGLTangentBuffer);
|
||||
c.vertexAttribPointer(n.tangent,4,c.FLOAT,false,0,0)}if(n.uv>=0)if(x.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,x.__webGLUVBuffer);c.enableVertexAttribArray(n.uv);c.vertexAttribPointer(n.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(n.uv);if(B){c.lineWidth(y);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.__webGLLineBuffer);c.drawElements(c.LINES,x.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,x.__webGLFaceCount,c.UNSIGNED_SHORT,
|
||||
0)}};this.renderPass=function(h,o,i,x,k,n){var B,y,L,F,O;L=0;for(F=i.material.length;L<F;L++){B=i.material[L];if(B instanceof THREE.MeshFaceMaterial){B=0;for(y=x.material.length;B<y;B++)if((O=x.material[B])&&O.blending==k&&O.opacity<1==n){this.setBlending(O.blending);this.renderBuffer(h,o,O,x)}}else if((O=B)&&O.blending==k&&O.opacity<1==n){this.setBlending(O.blending);this.renderBuffer(h,o,O,x)}}};this.render=function(h,o){var i,x,k,n,B=h.lights;this.initWebGLObjects(h);this.autoClear&&this.clear();
|
||||
o.autoUpdateMatrix&&o.updateMatrix();i=0;for(x=h.__webGLObjects.length;i<x;i++){k=h.__webGLObjects[i];n=k.object;k=k.buffer;if(n.visible){this.setupMatrices(n,o);this.renderPass(o,B,n,k,THREE.NormalBlending,false)}}i=0;for(x=h.__webGLObjects.length;i<x;i++){k=h.__webGLObjects[i];n=k.object;k=k.buffer;if(n.visible){this.setupMatrices(n,o);this.renderPass(o,B,n,k,THREE.AdditiveBlending,false);this.renderPass(o,B,n,k,THREE.SubtractiveBlending,false);this.renderPass(o,B,n,k,THREE.AdditiveBlending,true);
|
||||
this.renderPass(o,B,n,k,THREE.SubtractiveBlending,true);this.renderPass(o,B,n,k,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(h){var o,i,x,k,n,B;if(!h.__webGLObjects){h.__webGLObjects=[];h.__webGLObjectsMap={}}o=0;for(i=h.objects.length;o<i;o++){x=h.objects[o];if(h.__webGLObjectsMap[x.id]==undefined)h.__webGLObjectsMap[x.id]={};B=h.__webGLObjectsMap[x.id];if(x instanceof THREE.Mesh)for(n in x.geometry.geometryChunks){k=x.geometry.geometryChunks[n];k.__webGLVertexBuffer||this.createBuffers(x,
|
||||
n);if(B[n]==undefined){k={buffer:k,object:x};h.__webGLObjects.push(k);B[n]=1}}}};this.removeObject=function(h,o){var i,x;for(i=h.__webGLObjects.length-1;i>=0;i--){x=h.__webGLObjects[i].object;o==x&&h.__webGLObjects.splice(i,1)}};this.setupMatrices=function(h,o){h.autoUpdateMatrix&&h.updateMatrix();r.multiply(o.matrix,h.matrix);v.set(o.matrix.flatten());w.set(r.flatten());G.set(o.projectionMatrix.flatten());u=THREE.Matrix4.makeInvert3x3(r).transpose();H.set(u.m);A.set(h.matrix.flatten())};this.loadMatrices=
|
||||
function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,v);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,w);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,G);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,H);c.uniformMatrix4fv(h.uniforms.objectMatrix,false,A)};this.loadCamera=function(h,o){c.uniform3f(h.uniforms.cameraPosition,o.position.x,o.position.y,o.position.z)};this.setBlending=function(h){switch(h){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(h,o){if(h){!o||o=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(h=="back")c.cullFace(c.BACK);else h=="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}};
|
||||
THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
|
||||
THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
|
||||
var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,g=d?b.geometry:b,j=a.vertices,l=g.vertices,f=a.faces,p=g.faces,c=a.uvs;g=g.uvs;d&&b.updateMatrix();for(var t=0,C=l.length;t<C;t++){var r=new THREE.Vertex(l[t].position.clone());d&&b.matrix.multiplyVector3(r.position);j.push(r)}t=0;for(C=p.length;t<C;t++){l=p[t];var u,v=l.vertexNormals;if(l instanceof THREE.Face3)u=new THREE.Face3(l.a+e,l.b+e,l.c+e);else if(l instanceof THREE.Face4)u=new THREE.Face4(l.a+e,l.b+
|
||||
e,l.c+e,l.d+e);u.centroid.copy(l.centroid);u.normal.copy(l.normal);d=0;for(j=v.length;d<j;d++){r=v[d];u.vertexNormals.push(r.clone())}u.material=l.material.slice();f.push(u)}t=0;for(C=g.length;t<C;t++){e=g[t];f=[];d=0;for(j=e.length;d<j;d++)f.push(new THREE.UV(e[d].u,e[d].v));c.push(f)}}},ImageUtils={loadTexture:function(a,b){var d=new Image;d.onload=function(){this.loaded=true};d.src=a;return new THREE.Texture(d,b)},loadArray:function(a){var b,d,e=[];b=e.loadCount=0;for(d=a.length;b<d;++b){e[b]=
|
||||
new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=true};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,d,e,g,j,l,f,p,c){b=new THREE.Mesh(b,c);b.scale.x=b.scale.y=b.scale.z=d;b.position.x=e;b.position.y=g;b.position.z=j;b.rotation.x=l;b.rotation.y=f;b.rotation.z=p;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,d){d=new THREE.MeshCubeMaterial({env_map:d});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),d);a.addObject(b);return b},addPanoramaCube:function(a,
|
||||
b,d){var e=[];e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,e,true),new THREE.MeshFaceMaterial);a.addObject(mesh);
|
||||
return mesh},addPanoramaCubePlanes:function(a,b,d){var e=b/2;b=new Plane(b,b);var g=Math.PI/2,j=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-e,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-e,0,0,0,g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));SceneUtils.addMesh(a,b,1,e,0,0,0,-g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,e,0,g,0,j,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,
|
||||
b,1,0,-e,0,-g,0,j,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
|
||||
vertex_shader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"}}},
|
||||
Cube=function(a,b,d,e,g,j,l,f){function q(w,H,I,z,m,h,n,i){var y=e||1,k=g||1,o=y+1,B=k+1;m=m/y;h=h/k;var A=c.vertices.length,P;if(w=="x"&&H=="y"||w=="y"&&H=="x")P="z";else if(w=="x"&&H=="z"||w=="z"&&H=="x")P="y";else if(w=="z"&&H=="y"||w=="y"&&H=="z")P="x";for(iy=0;iy<B;iy++)for(ix=0;ix<o;ix++){var J=new THREE.Vector3;J[w]=(ix*m-t)*I;J[H]=(iy*h-D)*z;J[P]=n;c.vertices.push(new THREE.Vertex(J))}for(iy=0;iy<k;iy++)for(ix=0;ix<y;ix++){c.faces.push(new THREE.Face4(ix+o*iy+A,ix+o*(iy+1)+A,ix+1+o*(iy+1)+
|
||||
A,ix+1+o*iy+A,null,i));c.uvs.push([new THREE.UV(ix/y,iy/k),new THREE.UV(ix/y,(iy+1)/k),new THREE.UV((ix+1)/y,(iy+1)/k),new THREE.UV((ix+1)/y,iy/k)])}}THREE.Geometry.call(this);var c=this,t=a/2,D=b/2,r=d/2;l=l?-1:1;if(j!==undefined)if(j instanceof Array)this.materials=j;else{this.materials=[];for(var u=0;u<6;u++)this.materials.push([j])}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(f!=undefined)for(var v in f)if(this.sides[v]!=undefined)this.sides[v]=f[v];this.sides.px&&
|
||||
q("z","y",1*l,-1,d,b,-t,this.materials[0]);this.sides.nx&&q("z","y",-1*l,-1,d,b,t,this.materials[1]);this.sides.py&&q("x","z",1*l,1,a,d,D,this.materials[2]);this.sides.ny&&q("x","z",1*l,-1,a,d,-D,this.materials[3]);this.sides.pz&&q("x","y",1*l,-1,a,b,r,this.materials[4]);this.sides.nz&&q("x","y",-1*l,-1,a,b,-r,this.materials[5]);(function(){for(var w=[],H=[],I=0,z=c.vertices.length;I<z;I++){for(var m=c.vertices[I],h=false,n=0,i=w.length;n<i;n++){var y=w[n];if(m.position.x==y.position.x&&m.position.y==
|
||||
y.position.y&&m.position.z==y.position.z){H[I]=n;h=true;break}}if(!h){H[I]=w.length;w.push(new THREE.Vertex(m.position.clone()))}}I=0;for(z=c.faces.length;I<z;I++){m=c.faces[I];m.a=H[m.a];m.b=H[m.b];m.c=H[m.c];m.d=H[m.d]}c.vertices=w})();this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
|
||||
var Cylinder=function(a,b,d,e,g){function j(q,c,t){l.vertices.push(new THREE.Vertex(new THREE.Vector3(q,c,t)))}THREE.Geometry.call(this);var l=this,f;for(f=0;f<a;f++)j(Math.sin(6.283*f/a)*b,Math.cos(6.283*f/a)*b,0);for(f=0;f<a;f++)j(Math.sin(6.283*f/a)*d,Math.cos(6.283*f/a)*d,e);for(f=0;f<a;f++)l.faces.push(new THREE.Face4(f,f+a,a+(f+1)%a,(f+1)%a));if(d!=0){j(0,0,-g);for(f=a;f<a+a/2;f++)l.faces.push(new THREE.Face4(2*a,(2*f-2*a)%a,(2*f-2*a+1)%a,(2*f-2*a+2)%a))}if(b!=0){j(0,0,e+g);for(f=a+a/2;f<2*
|
||||
vertex_shader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"},
|
||||
normal:{uniforms:{tNormal:{type:"t",value:2,texture:null},tAO:{type:"t",value:3,texture:null},tDisplacement:{type:"t",value:4,texture:null},uDisplacementBias:{type:"f",value:-0.5},uDisplacementScale:{type:"f",value:2.5},uPointLightPos:{type:"v3",value:new THREE.Vector3},uPointLightColor:{type:"c",value:new THREE.Color(15658734)},uDirLightPos:{type:"v3",value:new THREE.Vector3},uDirLightColor:{type:"c",value:new THREE.Color(15658734)},uAmbientLightColor:{type:"c",value:new THREE.Color(328965)},uDiffuseColor:{type:"c",
|
||||
value:new THREE.Color(15658734)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(328965)},uShininess:{type:"f",value:30}},fragment_shader:"uniform vec3 uDirLightPos;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightPos;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform sampler2D tNormal;\nuniform sampler2D tAO;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 normalTex = normalize( texture2D( tNormal, vUv ).xyz * 2.0 - 1.0 );\nvec3 aoTex = texture2D( tAO, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec3 pointVector = normalize( vPointLightVector );\nvec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, uShininess );\npointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;\nvec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, uShininess );\ndirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;\nvec4 totalLight = vec4( uAmbientColor, 1.0 );\ntotalLight += dirDiffuse + dirSpecular;\ntotalLight += pointDiffuse + pointSpecular;\ngl_FragColor = vec4( totalLight.xyz * vLightWeighting * aoTex, 1.0 );\n}",
|
||||
vertex_shader:"attribute vec4 tangent;\nuniform vec3 uDirLightPos;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightPos;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientLightColor;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\nvLightWeighting = uAmbientLightColor;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );\nvLightWeighting += uPointLightColor * pointLightWeighting;\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nfloat directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += uDirLightColor * directionalLightWeighting;\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"}}},
|
||||
Cube=function(a,b,d,e,g,j,l,f){function p(w,G,H,A,m,h,o,i){var x=e||1,k=g||1,n=x+1,B=k+1;m=m/x;h=h/k;var y=c.vertices.length,L;if(w=="x"&&G=="y"||w=="y"&&G=="x")L="z";else if(w=="x"&&G=="z"||w=="z"&&G=="x")L="y";else if(w=="z"&&G=="y"||w=="y"&&G=="z")L="x";for(iy=0;iy<B;iy++)for(ix=0;ix<n;ix++){var F=new THREE.Vector3;F[w]=(ix*m-t)*H;F[G]=(iy*h-C)*A;F[L]=o;c.vertices.push(new THREE.Vertex(F))}for(iy=0;iy<k;iy++)for(ix=0;ix<x;ix++){c.faces.push(new THREE.Face4(ix+n*iy+y,ix+n*(iy+1)+y,ix+1+n*(iy+1)+
|
||||
y,ix+1+n*iy+y,null,i));c.uvs.push([new THREE.UV(ix/x,iy/k),new THREE.UV(ix/x,(iy+1)/k),new THREE.UV((ix+1)/x,(iy+1)/k),new THREE.UV((ix+1)/x,iy/k)])}}THREE.Geometry.call(this);var c=this,t=a/2,C=b/2,r=d/2;l=l?-1:1;if(j!==undefined)if(j instanceof Array)this.materials=j;else{this.materials=[];for(var u=0;u<6;u++)this.materials.push([j])}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(f!=undefined)for(var v in f)if(this.sides[v]!=undefined)this.sides[v]=f[v];this.sides.px&&
|
||||
p("z","y",1*l,-1,d,b,-t,this.materials[0]);this.sides.nx&&p("z","y",-1*l,-1,d,b,t,this.materials[1]);this.sides.py&&p("x","z",1*l,1,a,d,C,this.materials[2]);this.sides.ny&&p("x","z",1*l,-1,a,d,-C,this.materials[3]);this.sides.pz&&p("x","y",1*l,-1,a,b,r,this.materials[4]);this.sides.nz&&p("x","y",-1*l,-1,a,b,-r,this.materials[5]);(function(){for(var w=[],G=[],H=0,A=c.vertices.length;H<A;H++){for(var m=c.vertices[H],h=false,o=0,i=w.length;o<i;o++){var x=w[o];if(m.position.x==x.position.x&&m.position.y==
|
||||
x.position.y&&m.position.z==x.position.z){G[H]=o;h=true;break}}if(!h){G[H]=w.length;w.push(new THREE.Vertex(m.position.clone()))}}H=0;for(A=c.faces.length;H<A;H++){m=c.faces[H];m.a=G[m.a];m.b=G[m.b];m.c=G[m.c];m.d=G[m.d]}c.vertices=w})();this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
|
||||
var Cylinder=function(a,b,d,e,g){function j(p,c,t){l.vertices.push(new THREE.Vertex(new THREE.Vector3(p,c,t)))}THREE.Geometry.call(this);var l=this,f;for(f=0;f<a;f++)j(Math.sin(6.283*f/a)*b,Math.cos(6.283*f/a)*b,0);for(f=0;f<a;f++)j(Math.sin(6.283*f/a)*d,Math.cos(6.283*f/a)*d,e);for(f=0;f<a;f++)l.faces.push(new THREE.Face4(f,f+a,a+(f+1)%a,(f+1)%a));if(d!=0){j(0,0,-g);for(f=a;f<a+a/2;f++)l.faces.push(new THREE.Face4(2*a,(2*f-2*a)%a,(2*f-2*a+1)%a,(2*f-2*a+2)%a))}if(b!=0){j(0,0,e+g);for(f=a+a/2;f<2*
|
||||
a;f++)l.faces.push(new THREE.Face4((2*f-2*a+2)%a+a,(2*f-2*a+1)%a+a,(2*f-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
|
||||
var Plane=function(a,b,d,e){THREE.Geometry.call(this);var g,j=a/2,l=b/2;d=d||1;e=e||1;var f=d+1,q=e+1;a=a/d;var c=b/e;for(g=0;g<q;g++)for(b=0;b<f;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-j,-(g*c-l),0)));for(g=0;g<e;g++)for(b=0;b<d;b++){this.faces.push(new THREE.Face4(b+f*g,b+f*(g+1),b+1+f*(g+1),b+1+f*g));this.uvs.push([new THREE.UV(b/d,g/e),new THREE.UV(b/d,(g+1)/e),new THREE.UV((b+1)/d,(g+1)/e),new THREE.UV((b+1)/d,g/e)])}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};
|
||||
var Plane=function(a,b,d,e){THREE.Geometry.call(this);var g,j=a/2,l=b/2;d=d||1;e=e||1;var f=d+1,p=e+1;a=a/d;var c=b/e;for(g=0;g<p;g++)for(b=0;b<f;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-j,-(g*c-l),0)));for(g=0;g<e;g++)for(b=0;b<d;b++){this.faces.push(new THREE.Face4(b+f*g,b+f*(g+1),b+1+f*(g+1),b+1+f*g));this.uvs.push([new THREE.UV(b/d,g/e),new THREE.UV(b/d,(g+1)/e),new THREE.UV((b+1)/d,(g+1)/e),new THREE.UV((b+1)/d,g/e)])}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};
|
||||
Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
|
||||
var Sphere=function(a,b,d){THREE.Geometry.call(this);var e,g=Math.max(3,b||8),j=Math.max(2,d||6);b=[];for(d=0;d<j+1;d++){e=d/j;var l=a*Math.cos(e*Math.PI),f=a*Math.sin(e*Math.PI),q=[],c=0;for(e=0;e<g;e++){var t=2*e/g,D=f*Math.sin(t*Math.PI);t=f*Math.cos(t*Math.PI);(d==0||d==j)&&e>0||(c=this.vertices.push(new THREE.Vertex(new THREE.Vector3(t,l,D)))-1);q.push(c)}b.push(q)}var r,u,v;a=b.length;for(d=0;d<a;d++){g=b[d].length;if(d>0)for(e=0;e<g;e++){q=e==g-1;j=b[d][q?0:e+1];l=b[d][q?g-1:e];f=b[d-1][q?
|
||||
g-1:e];q=b[d-1][q?0:e+1];D=d/(a-1);r=(d-1)/(a-1);u=(e+1)/g;t=e/g;c=new THREE.UV(1-u,D);D=new THREE.UV(1-t,D);t=new THREE.UV(1-t,r);var w=new THREE.UV(1-u,r);if(d<b.length-1){r=this.vertices[j].position.clone();u=this.vertices[l].position.clone();v=this.vertices[f].position.clone();r.normalize();u.normalize();v.normalize();this.faces.push(new THREE.Face3(j,l,f,[new THREE.Vector3(r.x,r.y,r.z),new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,D,t])}if(d>1){r=this.vertices[j].position.clone();
|
||||
u=this.vertices[f].position.clone();v=this.vertices[q].position.clone();r.normalize();u.normalize();v.normalize();this.faces.push(new THREE.Face3(j,f,q,[new THREE.Vector3(r.x,r.y,r.z),new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,t,w])}}}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
|
||||
var Sphere=function(a,b,d){THREE.Geometry.call(this);var e,g=Math.max(3,b||8),j=Math.max(2,d||6);b=[];for(d=0;d<j+1;d++){e=d/j;var l=a*Math.cos(e*Math.PI),f=a*Math.sin(e*Math.PI),p=[],c=0;for(e=0;e<g;e++){var t=2*e/g,C=f*Math.sin(t*Math.PI);t=f*Math.cos(t*Math.PI);(d==0||d==j)&&e>0||(c=this.vertices.push(new THREE.Vertex(new THREE.Vector3(t,l,C)))-1);p.push(c)}b.push(p)}var r,u,v;a=b.length;for(d=0;d<a;d++){g=b[d].length;if(d>0)for(e=0;e<g;e++){p=e==g-1;j=b[d][p?0:e+1];l=b[d][p?g-1:e];f=b[d-1][p?
|
||||
g-1:e];p=b[d-1][p?0:e+1];C=d/(a-1);r=(d-1)/(a-1);u=(e+1)/g;t=e/g;c=new THREE.UV(1-u,C);C=new THREE.UV(1-t,C);t=new THREE.UV(1-t,r);var w=new THREE.UV(1-u,r);if(d<b.length-1){r=this.vertices[j].position.clone();u=this.vertices[l].position.clone();v=this.vertices[f].position.clone();r.normalize();u.normalize();v.normalize();this.faces.push(new THREE.Face3(j,l,f,[new THREE.Vector3(r.x,r.y,r.z),new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,C,t])}if(d>1){r=this.vertices[j].position.clone();
|
||||
u=this.vertices[f].position.clone();v=this.vertices[p].position.clone();r.normalize();u.normalize();v.normalize();this.faces.push(new THREE.Face3(j,f,p,[new THREE.Vector3(r.x,r.y,r.z),new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,t,w])}}}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};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 d=document.createElement("script");d.type="text/javascript";d.onload=b;d.src=a;document.getElementsByTagName("head")[0].appendChild(d)},loadAscii:function(a,b,d){var e=(new Date).getTime();a=new Worker(a);a.onmessage=function(g){THREE.Loader.prototype.createModel(g.data,b,d)};a.postMessage(e)},loadBinary:function(a,b,d){var e=(new Date).getTime();a=new Worker(a);var g=this.showProgress?THREE.Loader.prototype.updateProgress:null;a.onmessage=function(j){THREE.Loader.prototype.loadAjaxBuffers(j.data.buffers,
|
||||
j.data.materials,b,d,g)};a.onerror=function(j){alert("worker.onerror: "+j.message+"\n"+j.data);j.preventDefault()};a.postMessage(e)},loadAjaxBuffers:function(a,b,d,e,g){var j=new XMLHttpRequest,l=e+"/"+a,f=0;j.onreadystatechange=function(){if(j.readyState==4)j.status==200||j.status==0?THREE.Loader.prototype.createBinModel(j.responseText,d,e,b):alert("Couldn't load ["+l+"] ["+j.status+"]");else if(j.readyState==3){if(g){if(f==0)f=j.getResponseHeader("Content-Length");g({total:f,loaded:j.responseText.length})}}else if(j.readyState==
|
||||
2)f=j.getResponseHeader("Content-Length")};j.open("GET",l,true);j.overrideMimeType("text/plain; charset=x-user-defined");j.setRequestHeader("Content-Type","text/plain");j.send(null)},createBinModel:function(a,b,d,e){var g=function(j){function l(p,s){var x=t(p,s),G=t(p,s+1),V=t(p,s+2),ba=t(p,s+3),ga=(ba<<1&255|V>>7)-127;x=(V&127)<<16|G<<8|x;if(x==0&&ga==-127)return 0;return(1-2*(ba>>7))*(1+x*Math.pow(2,-23))*Math.pow(2,ga)}function f(p,s){var x=t(p,s),G=t(p,s+1),V=t(p,s+2);return(t(p,s+3)<<24)+(V<<
|
||||
16)+(G<<8)+x}function q(p,s){var x=t(p,s);return(t(p,s+1)<<8)+x}function c(p,s){var x=t(p,s);return x>127?x-256:x}function t(p,s){return p.charCodeAt(s)&255}function D(p){var s,x,G;s=f(a,p);x=f(a,p+i);G=f(a,p+y);p=q(a,p+k);THREE.Loader.prototype.f3(I,s,x,G,p)}function r(p){var s,x,G,V,ba,ga;s=f(a,p);x=f(a,p+i);G=f(a,p+y);V=q(a,p+k);ba=f(a,p+o);ga=f(a,p+B);p=f(a,p+A);THREE.Loader.prototype.f3n(I,h,s,x,G,V,ba,ga,p)}function u(p){var s,x,G,V;s=f(a,p);x=f(a,p+P);G=f(a,p+J);V=f(a,p+Q);p=q(a,p+T);THREE.Loader.prototype.f4(I,
|
||||
s,x,G,V,p)}function v(p){var s,x,G,V,ba,ga,$,ka;s=f(a,p);x=f(a,p+P);G=f(a,p+J);V=f(a,p+Q);ba=q(a,p+T);ga=f(a,p+E);$=f(a,p+U);ka=f(a,p+K);p=f(a,p+L);THREE.Loader.prototype.f4n(I,h,s,x,G,V,ba,ga,$,ka,p)}function w(p){var s,x;s=f(a,p);x=f(a,p+N);p=f(a,p+Y);THREE.Loader.prototype.uv3(I,n[s*2],n[s*2+1],n[x*2],n[x*2+1],n[p*2],n[p*2+1])}function H(p){var s,x,G;s=f(a,p);x=f(a,p+R);G=f(a,p+M);p=f(a,p+W);THREE.Loader.prototype.uv4(I,n[s*2],n[s*2+1],n[x*2],n[x*2+1],n[G*2],n[G*2+1],n[p*2],n[p*2+1])}var I=this,
|
||||
z=0,m,h=[],n=[],i,y,k,o,B,A,P,J,Q,T,E,U,K,L,N,Y,R,M,W;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(I,e,j);m={signature:a.substr(z,8),header_bytes:t(a,z+8),vertex_coordinate_bytes:t(a,z+9),normal_coordinate_bytes:t(a,z+10),uv_coordinate_bytes:t(a,z+11),vertex_index_bytes:t(a,z+12),normal_index_bytes:t(a,z+13),uv_index_bytes:t(a,z+14),material_index_bytes:t(a,z+15),nvertices:f(a,z+16),nnormals:f(a,z+16+4),nuvs:f(a,z+16+8),ntri_flat:f(a,z+16+12),ntri_smooth:f(a,z+16+16),ntri_flat_uv:f(a,
|
||||
z+16+20),ntri_smooth_uv:f(a,z+16+24),nquad_flat:f(a,z+16+28),nquad_smooth:f(a,z+16+32),nquad_flat_uv:f(a,z+16+36),nquad_smooth_uv:f(a,z+16+40)};z+=m.header_bytes;i=m.vertex_index_bytes;y=m.vertex_index_bytes*2;k=m.vertex_index_bytes*3;o=m.vertex_index_bytes*3+m.material_index_bytes;B=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;P=m.vertex_index_bytes;J=m.vertex_index_bytes*2;Q=m.vertex_index_bytes*3;T=m.vertex_index_bytes*
|
||||
4;E=m.vertex_index_bytes*4+m.material_index_bytes;U=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;L=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*3;N=m.uv_index_bytes;Y=m.uv_index_bytes*2;R=m.uv_index_bytes;M=m.uv_index_bytes*2;W=m.uv_index_bytes*3;z+=function(p){var s,x,G,V=m.vertex_coordinate_bytes*3,ba=p+m.nvertices*V;for(p=p;p<ba;p+=V){s=l(a,p);x=l(a,p+m.vertex_coordinate_bytes);G=
|
||||
l(a,p+m.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(I,s,x,G)}return m.nvertices*V}(z);z+=function(p){var s,x,G,V=m.normal_coordinate_bytes*3,ba=p+m.nnormals*V;for(p=p;p<ba;p+=V){s=c(a,p);x=c(a,p+m.normal_coordinate_bytes);G=c(a,p+m.normal_coordinate_bytes*2);h.push(s/127,x/127,G/127)}return m.nnormals*V}(z);z+=function(p){var s,x,G=m.uv_coordinate_bytes*2,V=p+m.nuvs*G;for(p=p;p<V;p+=G){s=l(a,p);x=l(a,p+m.uv_coordinate_bytes);n.push(s,x)}return m.nuvs*G}(z);z+=function(p){var s,x=m.vertex_index_bytes*
|
||||
3+m.material_index_bytes,G=p+m.ntri_flat*x;for(s=p;s<G;s+=x)D(s);return G-p}(z);z+=function(p){var s,x=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*3,G=p+m.ntri_smooth*x;for(s=p;s<G;s+=x)r(s);return G-p}(z);z+=function(p){var s,x=m.vertex_index_bytes*3+m.material_index_bytes,G=x+m.uv_index_bytes*3,V=p+m.ntri_flat_uv*G;for(s=p;s<V;s+=G){D(s);w(s+x)}return V-p}(z);z+=function(p){var s,x=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*3,G=x+m.uv_index_bytes*3,
|
||||
V=p+m.ntri_smooth_uv*G;for(s=p;s<V;s+=G){r(s);w(s+x)}return V-p}(z);z+=function(p){var s,x=m.vertex_index_bytes*4+m.material_index_bytes,G=p+m.nquad_flat*x;for(s=p;s<G;s+=x)u(s);return G-p}(z);z+=function(p){var s,x=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*4,G=p+m.nquad_smooth*x;for(s=p;s<G;s+=x)v(s);return G-p}(z);z+=function(p){var s,x=m.vertex_index_bytes*4+m.material_index_bytes,G=x+m.uv_index_bytes*4,V=p+m.nquad_flat_uv*G;for(s=p;s<V;s+=G){u(s);H(s+x)}return V-p}(z);
|
||||
z+=function(p){var s,x=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*4,G=x+m.uv_index_bytes*4,V=p+m.nquad_smooth_uv*G;for(s=p;s<V;s+=G){v(s);H(s+x)}return V-p}(z);this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;b(new g(d))},createModel:function(a,b,d){var e=function(g){var j=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(j,a.materials,g);(function(){var l,f,q,c,t;l=0;for(f=
|
||||
a.vertices.length;l<f;l+=3){q=a.vertices[l];c=a.vertices[l+1];t=a.vertices[l+2];THREE.Loader.prototype.v(j,q,c,t)}})();(function(){function l(v,w){THREE.Loader.prototype.f3(j,v[w],v[w+1],v[w+2],v[w+3])}function f(v,w){THREE.Loader.prototype.f3n(j,a.normals,v[w],v[w+1],v[w+2],v[w+3],v[w+4],v[w+5],v[w+6])}function q(v,w){THREE.Loader.prototype.f4(j,v[w],v[w+1],v[w+2],v[w+3],v[w+4])}function c(v,w){THREE.Loader.prototype.f4n(j,a.normals,v[w],v[w+1],v[w+2],v[w+3],v[w+4],v[w+5],v[w+6],v[w+7],v[w+8])}function t(v,
|
||||
w){var H,I,z;H=v[w];I=v[w+1];z=v[w+2];THREE.Loader.prototype.uv3(j,a.uvs[H*2],a.uvs[H*2+1],a.uvs[I*2],a.uvs[I*2+1],a.uvs[z*2],a.uvs[z*2+1])}function D(v,w){var H,I,z,m;H=v[w];I=v[w+1];z=v[w+2];m=v[w+3];THREE.Loader.prototype.uv4(j,a.uvs[H*2],a.uvs[H*2+1],a.uvs[I*2],a.uvs[I*2+1],a.uvs[z*2],a.uvs[z*2+1],a.uvs[m*2],a.uvs[m*2+1])}var r,u;r=0;for(u=a.triangles.length;r<u;r+=4)l(a.triangles,r);r=0;for(u=a.triangles_uv.length;r<u;r+=7){l(a.triangles_uv,r);t(a.triangles_uv,r+4)}r=0;for(u=a.triangles_n.length;r<
|
||||
u;r+=7)f(a.triangles_n,r);r=0;for(u=a.triangles_n_uv.length;r<u;r+=10){f(a.triangles_n_uv,r);t(a.triangles_n_uv,r+7)}r=0;for(u=a.quads.length;r<u;r+=5)q(a.quads,r);r=0;for(u=a.quads_uv.length;r<u;r+=9){q(a.quads_uv,r);D(a.quads_uv,r+5)}r=0;for(u=a.quads_n.length;r<u;r+=9)c(a.quads_n,r);r=0;for(u=a.quads_n_uv.length;r<u;r+=13){c(a.quads_n_uv,r);D(a.quads_n_uv,r+9)}})();this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};e.prototype=new THREE.Geometry;e.prototype.constructor=e;
|
||||
b(new e(d))},v:function(a,b,d,e){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,d,e)))},f3:function(a,b,d,e,g){a.faces.push(new THREE.Face3(b,d,e,null,a.materials[g]))},f4:function(a,b,d,e,g,j){a.faces.push(new THREE.Face4(b,d,e,g,null,a.materials[j]))},f3n:function(a,b,d,e,g,j,l,f,q){j=a.materials[j];var c=b[f*3],t=b[f*3+1];f=b[f*3+2];var D=b[q*3],r=b[q*3+1];q=b[q*3+2];a.faces.push(new THREE.Face3(d,e,g,[new THREE.Vector3(b[l*3],b[l*3+1],b[l*3+2]),new THREE.Vector3(c,t,f),new THREE.Vector3(D,
|
||||
r,q)],j))},f4n:function(a,b,d,e,g,j,l,f,q,c,t){l=a.materials[l];var D=b[q*3],r=b[q*3+1];q=b[q*3+2];var u=b[c*3],v=b[c*3+1];c=b[c*3+2];var w=b[t*3],H=b[t*3+1];t=b[t*3+2];a.faces.push(new THREE.Face4(d,e,g,j,[new THREE.Vector3(b[f*3],b[f*3+1],b[f*3+2]),new THREE.Vector3(D,r,q),new THREE.Vector3(u,v,c),new THREE.Vector3(w,H,t)],l))},uv3:function(a,b,d,e,g,j,l){var f=[];f.push(new THREE.UV(b,d));f.push(new THREE.UV(e,g));f.push(new THREE.UV(j,l));a.uvs.push(f)},uv4:function(a,b,d,e,g,j,l,f,q){var c=[];
|
||||
c.push(new THREE.UV(b,d));c.push(new THREE.UV(e,g));c.push(new THREE.UV(j,l));c.push(new THREE.UV(f,q));a.uvs.push(c)},init_materials:function(a,b,d){a.materials=[];for(var e=0;e<b.length;++e)a.materials[e]=[THREE.Loader.prototype.createMaterial(b[e],d)]},createMaterial:function(a,b){function d(j){j=Math.log(j)/Math.LN2;return Math.floor(j)==j}var e,g;if(a.map_diffuse&&b){g=document.createElement("canvas");e=new THREE.MeshLambertMaterial({map:new THREE.Texture(g)});g=new Image;g.onload=function(){if(!d(this.width)||
|
||||
2)f=j.getResponseHeader("Content-Length")};j.open("GET",l,true);j.overrideMimeType("text/plain; charset=x-user-defined");j.setRequestHeader("Content-Type","text/plain");j.send(null)},createBinModel:function(a,b,d,e){var g=function(j){function l(q,s){var z=t(q,s),J=t(q,s+1),W=t(q,s+2),ba=t(q,s+3),ga=(ba<<1&255|W>>7)-127;z=(W&127)<<16|J<<8|z;if(z==0&&ga==-127)return 0;return(1-2*(ba>>7))*(1+z*Math.pow(2,-23))*Math.pow(2,ga)}function f(q,s){var z=t(q,s),J=t(q,s+1),W=t(q,s+2);return(t(q,s+3)<<24)+(W<<
|
||||
16)+(J<<8)+z}function p(q,s){var z=t(q,s);return(t(q,s+1)<<8)+z}function c(q,s){var z=t(q,s);return z>127?z-256:z}function t(q,s){return q.charCodeAt(s)&255}function C(q){var s,z,J;s=f(a,q);z=f(a,q+i);J=f(a,q+x);q=p(a,q+k);THREE.Loader.prototype.f3(H,s,z,J,q)}function r(q){var s,z,J,W,ba,ga;s=f(a,q);z=f(a,q+i);J=f(a,q+x);W=p(a,q+k);ba=f(a,q+n);ga=f(a,q+B);q=f(a,q+y);THREE.Loader.prototype.f3n(H,h,s,z,J,W,ba,ga,q)}function u(q){var s,z,J,W;s=f(a,q);z=f(a,q+L);J=f(a,q+F);W=f(a,q+O);q=p(a,q+V);THREE.Loader.prototype.f4(H,
|
||||
s,z,J,W,q)}function v(q){var s,z,J,W,ba,ga,$,ka;s=f(a,q);z=f(a,q+L);J=f(a,q+F);W=f(a,q+O);ba=p(a,q+V);ga=f(a,q+E);$=f(a,q+S);ka=f(a,q+N);q=f(a,q+T);THREE.Loader.prototype.f4n(H,h,s,z,J,W,ba,ga,$,ka,q)}function w(q){var s,z;s=f(a,q);z=f(a,q+U);q=f(a,q+Q);THREE.Loader.prototype.uv3(H,o[s*2],o[s*2+1],o[z*2],o[z*2+1],o[q*2],o[q*2+1])}function G(q){var s,z,J;s=f(a,q);z=f(a,q+K);J=f(a,q+M);q=f(a,q+X);THREE.Loader.prototype.uv4(H,o[s*2],o[s*2+1],o[z*2],o[z*2+1],o[J*2],o[J*2+1],o[q*2],o[q*2+1])}var H=this,
|
||||
A=0,m,h=[],o=[],i,x,k,n,B,y,L,F,O,V,E,S,N,T,U,Q,K,M,X;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(H,e,j);m={signature:a.substr(A,8),header_bytes:t(a,A+8),vertex_coordinate_bytes:t(a,A+9),normal_coordinate_bytes:t(a,A+10),uv_coordinate_bytes:t(a,A+11),vertex_index_bytes:t(a,A+12),normal_index_bytes:t(a,A+13),uv_index_bytes:t(a,A+14),material_index_bytes:t(a,A+15),nvertices:f(a,A+16),nnormals:f(a,A+16+4),nuvs:f(a,A+16+8),ntri_flat:f(a,A+16+12),ntri_smooth:f(a,A+16+16),ntri_flat_uv:f(a,
|
||||
A+16+20),ntri_smooth_uv:f(a,A+16+24),nquad_flat:f(a,A+16+28),nquad_smooth:f(a,A+16+32),nquad_flat_uv:f(a,A+16+36),nquad_smooth_uv:f(a,A+16+40)};A+=m.header_bytes;i=m.vertex_index_bytes;x=m.vertex_index_bytes*2;k=m.vertex_index_bytes*3;n=m.vertex_index_bytes*3+m.material_index_bytes;B=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes;y=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*2;L=m.vertex_index_bytes;F=m.vertex_index_bytes*2;O=m.vertex_index_bytes*3;V=m.vertex_index_bytes*
|
||||
4;E=m.vertex_index_bytes*4+m.material_index_bytes;S=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes;N=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*2;T=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*3;U=m.uv_index_bytes;Q=m.uv_index_bytes*2;K=m.uv_index_bytes;M=m.uv_index_bytes*2;X=m.uv_index_bytes*3;A+=function(q){var s,z,J,W=m.vertex_coordinate_bytes*3,ba=q+m.nvertices*W;for(q=q;q<ba;q+=W){s=l(a,q);z=l(a,q+m.vertex_coordinate_bytes);J=
|
||||
l(a,q+m.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(H,s,z,J)}return m.nvertices*W}(A);A+=function(q){var s,z,J,W=m.normal_coordinate_bytes*3,ba=q+m.nnormals*W;for(q=q;q<ba;q+=W){s=c(a,q);z=c(a,q+m.normal_coordinate_bytes);J=c(a,q+m.normal_coordinate_bytes*2);h.push(s/127,z/127,J/127)}return m.nnormals*W}(A);A+=function(q){var s,z,J=m.uv_coordinate_bytes*2,W=q+m.nuvs*J;for(q=q;q<W;q+=J){s=l(a,q);z=l(a,q+m.uv_coordinate_bytes);o.push(s,z)}return m.nuvs*J}(A);A+=function(q){var s,z=m.vertex_index_bytes*
|
||||
3+m.material_index_bytes,J=q+m.ntri_flat*z;for(s=q;s<J;s+=z)C(s);return J-q}(A);A+=function(q){var s,z=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*3,J=q+m.ntri_smooth*z;for(s=q;s<J;s+=z)r(s);return J-q}(A);A+=function(q){var s,z=m.vertex_index_bytes*3+m.material_index_bytes,J=z+m.uv_index_bytes*3,W=q+m.ntri_flat_uv*J;for(s=q;s<W;s+=J){C(s);w(s+z)}return W-q}(A);A+=function(q){var s,z=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*3,J=z+m.uv_index_bytes*3,
|
||||
W=q+m.ntri_smooth_uv*J;for(s=q;s<W;s+=J){r(s);w(s+z)}return W-q}(A);A+=function(q){var s,z=m.vertex_index_bytes*4+m.material_index_bytes,J=q+m.nquad_flat*z;for(s=q;s<J;s+=z)u(s);return J-q}(A);A+=function(q){var s,z=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*4,J=q+m.nquad_smooth*z;for(s=q;s<J;s+=z)v(s);return J-q}(A);A+=function(q){var s,z=m.vertex_index_bytes*4+m.material_index_bytes,J=z+m.uv_index_bytes*4,W=q+m.nquad_flat_uv*J;for(s=q;s<W;s+=J){u(s);G(s+z)}return W-q}(A);
|
||||
A+=function(q){var s,z=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*4,J=z+m.uv_index_bytes*4,W=q+m.nquad_smooth_uv*J;for(s=q;s<W;s+=J){v(s);G(s+z)}return W-q}(A);this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;b(new g(d))},createModel:function(a,b,d){var e=function(g){var j=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(j,a.materials,g);(function(){var l,f,p,c,t;l=0;for(f=
|
||||
a.vertices.length;l<f;l+=3){p=a.vertices[l];c=a.vertices[l+1];t=a.vertices[l+2];THREE.Loader.prototype.v(j,p,c,t)}})();(function(){function l(v,w){THREE.Loader.prototype.f3(j,v[w],v[w+1],v[w+2],v[w+3])}function f(v,w){THREE.Loader.prototype.f3n(j,a.normals,v[w],v[w+1],v[w+2],v[w+3],v[w+4],v[w+5],v[w+6])}function p(v,w){THREE.Loader.prototype.f4(j,v[w],v[w+1],v[w+2],v[w+3],v[w+4])}function c(v,w){THREE.Loader.prototype.f4n(j,a.normals,v[w],v[w+1],v[w+2],v[w+3],v[w+4],v[w+5],v[w+6],v[w+7],v[w+8])}function t(v,
|
||||
w){var G,H,A;G=v[w];H=v[w+1];A=v[w+2];THREE.Loader.prototype.uv3(j,a.uvs[G*2],a.uvs[G*2+1],a.uvs[H*2],a.uvs[H*2+1],a.uvs[A*2],a.uvs[A*2+1])}function C(v,w){var G,H,A,m;G=v[w];H=v[w+1];A=v[w+2];m=v[w+3];THREE.Loader.prototype.uv4(j,a.uvs[G*2],a.uvs[G*2+1],a.uvs[H*2],a.uvs[H*2+1],a.uvs[A*2],a.uvs[A*2+1],a.uvs[m*2],a.uvs[m*2+1])}var r,u;r=0;for(u=a.triangles.length;r<u;r+=4)l(a.triangles,r);r=0;for(u=a.triangles_uv.length;r<u;r+=7){l(a.triangles_uv,r);t(a.triangles_uv,r+4)}r=0;for(u=a.triangles_n.length;r<
|
||||
u;r+=7)f(a.triangles_n,r);r=0;for(u=a.triangles_n_uv.length;r<u;r+=10){f(a.triangles_n_uv,r);t(a.triangles_n_uv,r+7)}r=0;for(u=a.quads.length;r<u;r+=5)p(a.quads,r);r=0;for(u=a.quads_uv.length;r<u;r+=9){p(a.quads_uv,r);C(a.quads_uv,r+5)}r=0;for(u=a.quads_n.length;r<u;r+=9)c(a.quads_n,r);r=0;for(u=a.quads_n_uv.length;r<u;r+=13){c(a.quads_n_uv,r);C(a.quads_n_uv,r+9)}})();this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};e.prototype=new THREE.Geometry;e.prototype.constructor=e;
|
||||
b(new e(d))},v:function(a,b,d,e){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,d,e)))},f3:function(a,b,d,e,g){a.faces.push(new THREE.Face3(b,d,e,null,a.materials[g]))},f4:function(a,b,d,e,g,j){a.faces.push(new THREE.Face4(b,d,e,g,null,a.materials[j]))},f3n:function(a,b,d,e,g,j,l,f,p){j=a.materials[j];var c=b[f*3],t=b[f*3+1];f=b[f*3+2];var C=b[p*3],r=b[p*3+1];p=b[p*3+2];a.faces.push(new THREE.Face3(d,e,g,[new THREE.Vector3(b[l*3],b[l*3+1],b[l*3+2]),new THREE.Vector3(c,t,f),new THREE.Vector3(C,
|
||||
r,p)],j))},f4n:function(a,b,d,e,g,j,l,f,p,c,t){l=a.materials[l];var C=b[p*3],r=b[p*3+1];p=b[p*3+2];var u=b[c*3],v=b[c*3+1];c=b[c*3+2];var w=b[t*3],G=b[t*3+1];t=b[t*3+2];a.faces.push(new THREE.Face4(d,e,g,j,[new THREE.Vector3(b[f*3],b[f*3+1],b[f*3+2]),new THREE.Vector3(C,r,p),new THREE.Vector3(u,v,c),new THREE.Vector3(w,G,t)],l))},uv3:function(a,b,d,e,g,j,l){var f=[];f.push(new THREE.UV(b,d));f.push(new THREE.UV(e,g));f.push(new THREE.UV(j,l));a.uvs.push(f)},uv4:function(a,b,d,e,g,j,l,f,p){var c=[];
|
||||
c.push(new THREE.UV(b,d));c.push(new THREE.UV(e,g));c.push(new THREE.UV(j,l));c.push(new THREE.UV(f,p));a.uvs.push(c)},init_materials:function(a,b,d){a.materials=[];for(var e=0;e<b.length;++e)a.materials[e]=[THREE.Loader.prototype.createMaterial(b[e],d)]},createMaterial:function(a,b){function d(j){j=Math.log(j)/Math.LN2;return Math.floor(j)==j}var e,g;if(a.map_diffuse&&b){g=document.createElement("canvas");e=new THREE.MeshLambertMaterial({map:new THREE.Texture(g)});g=new Image;g.onload=function(){if(!d(this.width)||
|
||||
!d(this.height)){var j=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),l=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));e.map.image.width=j;e.map.image.height=l;e.map.image.getContext("2d").drawImage(this,0,0,j,l)}else e.map.image=this;e.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;e=new THREE.MeshLambertMaterial({color:g,opacity:a.transparency})}else e=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):
|
||||
new THREE.MeshLambertMaterial({color:15658734});return e}};
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>three.js - webgl normal map</title>
|
||||
<meta charset="utf-8">
|
||||
<style type="text/css">
|
||||
body {
|
||||
background:#000;
|
||||
color:#fff;
|
||||
padding:0;
|
||||
margin:0;
|
||||
font-weight: bold;
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
a { color: #ffffff; }
|
||||
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 0px; width: 100%;
|
||||
color: #ffffff;
|
||||
padding: 5px;
|
||||
font-family:Monospace;
|
||||
font-size:13px;
|
||||
text-align:center;
|
||||
z-index:1000;
|
||||
}
|
||||
|
||||
#oldie {
|
||||
font-family:monospace;
|
||||
font-size:13px;
|
||||
|
||||
text-align:center;
|
||||
background:rgb(200,100,0);
|
||||
color:#fff;
|
||||
padding:1em;
|
||||
|
||||
width:475px;
|
||||
margin:5em auto 0;
|
||||
|
||||
border:solid 2px #fff;
|
||||
border-radius:10px;
|
||||
|
||||
display:none;
|
||||
}
|
||||
|
||||
#vt { display:none }
|
||||
#vt, #vt a { color:orange; }
|
||||
.code { }
|
||||
|
||||
#log { position:absolute; top:50px; text-align:left; display:block; z-index:100 }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<pre id="log"></pre>
|
||||
|
||||
<div id="info">
|
||||
<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl (<span id="description">normal + ao + displacement</span>) map demo.
|
||||
ninja head from <a href="http://developer.amd.com/archive/gpu/MeshMapper/pages/default.aspx" target="_blank">AMD GPU MeshMapper</a>
|
||||
|
||||
<div id="vt">displacement mapping needs vertex textures (GPU with Shader Model 3.0)<br/>
|
||||
on Windows use <span class="code">Chrome --use-gl=desktop</span> or Firefox 4<br/>
|
||||
please star this <a href="http://code.google.com/p/chromium/issues/detail?id=52497">Chrome issue</a> to get ANGLE support
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<center>
|
||||
<div id="oldie">
|
||||
Sorry, your browser doesn't support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>
|
||||
and <a href="http://www.whatwg.org/specs/web-workers/current-work/">Web Workers</a>.<br/>
|
||||
<br/>
|
||||
Please try in
|
||||
<a href="http://www.chromium.org/getting-involved/dev-channel">Chrome 9+</a> /
|
||||
<a href="http://www.mozilla.com/en-US/firefox/all-beta.html">Firefox 4+</a> /
|
||||
<a href="http://nightly.webkit.org/">Safari OSX 10.6+</a>
|
||||
</div>
|
||||
</center>
|
||||
|
||||
<script type="text/javascript" src="../build/ThreeExtras.js"></script>
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
if ( !is_browser_compatible() ) {
|
||||
|
||||
document.getElementById( "oldie" ).style.display = "block";
|
||||
|
||||
}
|
||||
|
||||
var statsEnabled = true;
|
||||
|
||||
var container, stats, loader;
|
||||
|
||||
var camera, scene, webglRenderer;
|
||||
|
||||
var mesh, zmesh, lightMesh, geometry;
|
||||
var mesh1, mesh2;
|
||||
|
||||
var directionalLight, pointLight, ambientLight;
|
||||
|
||||
var mouseX = 0;
|
||||
var mouseY = 0;
|
||||
|
||||
var windowHalfX = window.innerWidth / 2;
|
||||
var windowHalfY = window.innerHeight / 2;
|
||||
|
||||
var r = 0.0;
|
||||
|
||||
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
|
||||
|
||||
init();
|
||||
setInterval( loop, 1000 / 60 );
|
||||
|
||||
function init() {
|
||||
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
|
||||
camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
|
||||
camera.projectionMatrix = THREE.Matrix4.makeOrtho( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -10000, 10000 );
|
||||
camera.position.z = 6200;
|
||||
|
||||
scene = new THREE.Scene();
|
||||
|
||||
// LIGHTS
|
||||
|
||||
ambientLight = new THREE.AmbientLight( 0x111111 );
|
||||
scene.addLight( ambientLight );
|
||||
|
||||
pointLight = new THREE.PointLight( 0xffff55 );
|
||||
pointLight.position.z = 10000;
|
||||
scene.addLight( pointLight );
|
||||
|
||||
directionalLight = new THREE.DirectionalLight( 0xaaaa88 );
|
||||
directionalLight.position.x = 1;
|
||||
directionalLight.position.y = 1;
|
||||
directionalLight.position.z = 0.5;
|
||||
directionalLight.position.normalize();
|
||||
scene.addLight( directionalLight );
|
||||
|
||||
// light representation
|
||||
|
||||
var sphere = new Sphere( 100, 16, 8, 1 );
|
||||
lightMesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color:0xffaa00 } ) );
|
||||
lightMesh.position = pointLight.position;
|
||||
lightMesh.scale.x = lightMesh.scale.y = lightMesh.scale.z = 0.05;
|
||||
scene.addObject(lightMesh);
|
||||
|
||||
// common material parameters
|
||||
|
||||
var ambient = 0x050505, diffuse = 0x555555, specular = 0xaa6600, shininess = 10, scale = 23;
|
||||
|
||||
// normal map shader
|
||||
|
||||
var fragment_shader = ShaderUtils.lib[ "normal" ].fragment_shader;
|
||||
var vertex_shader = ShaderUtils.lib[ "normal" ].vertex_shader;
|
||||
var uniforms = ShaderUtils.lib[ "normal" ].uniforms;
|
||||
|
||||
uniforms[ "tNormal" ].texture = ImageUtils.loadTexture( "textures/normal/ninja/normal.jpg" );
|
||||
uniforms[ "tAO" ].texture = ImageUtils.loadTexture( "textures/normal/ninja/ao.jpg" );
|
||||
|
||||
uniforms[ "tDisplacement" ].texture = ImageUtils.loadTexture( "textures/normal/ninja/displacement.jpg" );
|
||||
uniforms[ "uDisplacementBias" ].value = -0.428408 * scale;
|
||||
uniforms[ "uDisplacementScale" ].value = 2.436143 * scale;
|
||||
|
||||
uniforms[ "uPointLightPos" ].value = pointLight.position;
|
||||
uniforms[ "uPointLightColor" ].value = pointLight.color;
|
||||
|
||||
uniforms[ "uDirLightPos" ].value = directionalLight.position;
|
||||
uniforms[ "uDirLightColor" ].value = directionalLight.color;
|
||||
|
||||
uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
|
||||
|
||||
uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
|
||||
uniforms[ "uSpecularColor" ].value.setHex( specular );
|
||||
uniforms[ "uAmbientColor" ].value.setHex( ambient );
|
||||
|
||||
uniforms[ "uShininess" ].value = shininess;
|
||||
|
||||
var material1 = new THREE.MeshShaderMaterial( { fragment_shader: fragment_shader,
|
||||
vertex_shader: vertex_shader,
|
||||
uniforms: uniforms
|
||||
} );
|
||||
|
||||
var material2 = new THREE.MeshPhongMaterial( { color: diffuse, specular: specular, ambient: ambient, shininess: shininess } );
|
||||
|
||||
loader = new THREE.Loader( true );
|
||||
document.body.appendChild( loader.statusDomElement );
|
||||
|
||||
loader.loadBinary( "obj/ninja/NinjaLo_bin.js", function( geometry ) { createScene( geometry, scale, material1, material2 ) }, "obj/ninja" );
|
||||
|
||||
webglRenderer = new THREE.WebGLRenderer( scene );
|
||||
webglRenderer.setSize( window.innerWidth, window.innerHeight );
|
||||
container.appendChild( webglRenderer.domElement );
|
||||
|
||||
var description = "normal + ao" + ( webglRenderer.supportsVertexTextures() ? " + displacement" : " + <strike>displacement</strike>" );
|
||||
document.getElementById( "description" ).innerHTML = description;
|
||||
document.getElementById( "vt" ).style.display = webglRenderer.supportsVertexTextures() ? "none" : "block";
|
||||
|
||||
if ( statsEnabled ) {
|
||||
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
stats.domElement.style.zIndex = 100;
|
||||
container.appendChild( stats.domElement );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function createScene( geometry, scale, material1, material2 ) {
|
||||
|
||||
geometry.computeTangents();
|
||||
|
||||
mesh1 = SceneUtils.addMesh( scene, geometry, scale, -scale * 12, 0, 0, 0,0,0, material1 );
|
||||
mesh2 = SceneUtils.addMesh( scene, geometry, scale, scale * 12, 0, 0, 0,0,0, material2 );
|
||||
|
||||
loader.statusDomElement.style.display = "none";
|
||||
|
||||
}
|
||||
|
||||
function onDocumentMouseMove(event) {
|
||||
|
||||
mouseX = ( event.clientX - windowHalfX ) * 10;
|
||||
mouseY = ( event.clientY - windowHalfY ) * 10;
|
||||
|
||||
}
|
||||
|
||||
function loop() {
|
||||
|
||||
var ry = mouseX * 0.0003, rx = mouseY * 0.0003;
|
||||
|
||||
if( mesh1 ) {
|
||||
|
||||
mesh1.rotation.y = ry;
|
||||
mesh1.rotation.x = rx;
|
||||
|
||||
}
|
||||
|
||||
if( mesh2 ) {
|
||||
|
||||
mesh2.rotation.y = ry;
|
||||
mesh2.rotation.x = rx;
|
||||
|
||||
}
|
||||
|
||||
lightMesh.position.x = 2500 * Math.cos( r );
|
||||
lightMesh.position.z = 2500 * Math.sin( r );
|
||||
|
||||
r += 0.01;
|
||||
|
||||
webglRenderer.render( scene, camera );
|
||||
|
||||
if ( statsEnabled ) stats.update();
|
||||
|
||||
}
|
||||
|
||||
function log( text ) {
|
||||
|
||||
var e = document.getElementById("log");
|
||||
e.innerHTML = text + "<br/>" + e.innerHTML;
|
||||
|
||||
}
|
||||
|
||||
function is_browser_compatible() {
|
||||
|
||||
// WebGL support
|
||||
|
||||
try { var test = new Float32Array(1); } catch(e) { return false; }
|
||||
|
||||
// Web workers
|
||||
|
||||
return !!window.Worker;
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,7 @@
|
||||
<Files *.js>
|
||||
SetOutputFilter DEFLATE
|
||||
</Files>
|
||||
|
||||
<Files *.bin>
|
||||
SetOutputFilter DEFLATE
|
||||
</Files>
|
||||
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
// Converted from: ../../examples/obj/ninja/ninjaHead_Low.obj
|
||||
// vertices: 4485
|
||||
// faces: 4810
|
||||
// materials: 0
|
||||
//
|
||||
// Generated with OBJ -> Three.js converter
|
||||
// http://github.com/alteredq/three.js/blob/master/utils/exporters/convert_obj_threejs_slim.py
|
||||
|
||||
|
||||
var model = {
|
||||
'materials': [ {
|
||||
"a_dbg_color" : 0xeeeeee,
|
||||
"a_dbg_index" : 0,
|
||||
"a_dbg_name" : "default"
|
||||
}],
|
||||
|
||||
'buffers': 'NinjaLo_bin.bin',
|
||||
|
||||
'end': (new Date).getTime()
|
||||
}
|
||||
|
||||
postMessage( model );
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 87 KiB |
@@ -0,0 +1,2 @@
|
||||
DisplacementMap Scale: 2.436143
|
||||
DisplacementMap Bias : -0.428408
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 164 KiB |
@@ -12,6 +12,8 @@ THREE.Geometry = function () {
|
||||
|
||||
this.geometryChunks = {};
|
||||
|
||||
this.hasTangents = false;
|
||||
|
||||
};
|
||||
|
||||
THREE.Geometry.prototype = {
|
||||
@@ -167,6 +169,121 @@ THREE.Geometry.prototype = {
|
||||
|
||||
},
|
||||
|
||||
computeTangents: function() {
|
||||
|
||||
// based on http://www.terathon.com/code/tangent.html
|
||||
// tangents go to vertices
|
||||
|
||||
var f, fl, v, vl, face, uv, vA, vB, vC, uvA, uvB, uvC,
|
||||
x1, x2, y1, y2, z1, z2,
|
||||
s1, s2, t1, t2, r, t, n,
|
||||
tan1 = [], tan2 = [],
|
||||
sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
|
||||
tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
|
||||
n = new THREE.Vector3(), w;
|
||||
|
||||
for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
|
||||
|
||||
tan1[ v ] = new THREE.Vector3();
|
||||
tan2[ v ] = new THREE.Vector3();
|
||||
|
||||
}
|
||||
|
||||
function handleTriangle( context, a, b, c ) {
|
||||
|
||||
vA = context.vertices[ a ].position;
|
||||
vB = context.vertices[ b ].position;
|
||||
vC = context.vertices[ c ].position;
|
||||
|
||||
uvA = uv[ 0 ];
|
||||
uvB = uv[ 1 ];
|
||||
uvC = uv[ 2 ];
|
||||
|
||||
x1 = vB.x - vA.x;
|
||||
x2 = vC.x - vA.x;
|
||||
y1 = vB.y - vA.y;
|
||||
y2 = vC.y - vA.y;
|
||||
z1 = vB.z - vA.z;
|
||||
z2 = vC.z - vA.z;
|
||||
|
||||
s1 = uvB.u - uvA.u;
|
||||
s2 = uvC.u - uvA.u;
|
||||
t1 = uvB.v - uvA.v;
|
||||
t2 = uvC.v - uvA.v;
|
||||
|
||||
r = 1.0 / ( s1 * t2 - s2 * t1 );
|
||||
sdir.set( ( t2 * x1 - t1 * x2 ) * r,
|
||||
( t2 * y1 - t1 * y2 ) * r,
|
||||
( t2 * z1 - t1 * z2 ) * r );
|
||||
tdir.set( ( s1 * x2 - s2 * x1 ) * r,
|
||||
( s1 * y2 - s2 * y1 ) * r,
|
||||
( s1 * z2 - s2 * z1 ) * r );
|
||||
|
||||
tan1[ a ].addSelf( sdir );
|
||||
tan1[ b ].addSelf( sdir );
|
||||
tan1[ c ].addSelf( sdir );
|
||||
|
||||
tan2[ a ].addSelf( tdir );
|
||||
tan2[ b ].addSelf( tdir );
|
||||
tan2[ c ].addSelf( tdir );
|
||||
|
||||
}
|
||||
|
||||
for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
|
||||
|
||||
face = this.faces[ f ];
|
||||
uv = this.uvs[ f ];
|
||||
|
||||
if ( face instanceof THREE.Face3 ) {
|
||||
|
||||
handleTriangle( this, face.a, face.b, face.c );
|
||||
|
||||
this.vertices[ face.a ].normal.copy( face.vertexNormals[ 0 ] );
|
||||
this.vertices[ face.b ].normal.copy( face.vertexNormals[ 1 ] );
|
||||
this.vertices[ face.c ].normal.copy( face.vertexNormals[ 2 ] );
|
||||
|
||||
|
||||
} else if ( face instanceof THREE.Face4 ) {
|
||||
|
||||
handleTriangle( this, face.a, face.b, face.c );
|
||||
|
||||
// this messes up everything
|
||||
// quads need to be handled differently
|
||||
//handleTriangle( this, face.a, face.c, face.d );
|
||||
|
||||
this.vertices[ face.a ].normal.copy( face.vertexNormals[ 0 ] );
|
||||
this.vertices[ face.b ].normal.copy( face.vertexNormals[ 1 ] );
|
||||
this.vertices[ face.c ].normal.copy( face.vertexNormals[ 2 ] );
|
||||
this.vertices[ face.d ].normal.copy( face.vertexNormals[ 3 ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
|
||||
|
||||
n.copy( this.vertices[ v ].normal );
|
||||
t = tan1[ v ];
|
||||
|
||||
// Gram-Schmidt orthogonalize
|
||||
|
||||
tmp.copy( t );
|
||||
tmp.subSelf( n.multiplyScalar( n.dot( t ) ) ).normalize();
|
||||
|
||||
// Calculate handedness
|
||||
|
||||
tmp2.cross( this.vertices[ v ].normal, t );
|
||||
test = tmp2.dot( tan2[ v ] );
|
||||
w = (test < 0.0) ? -1.0 : 1.0;
|
||||
|
||||
this.vertices[ v ].tangent.set( tmp.x, tmp.y, tmp.z, w );
|
||||
|
||||
}
|
||||
|
||||
this.hasTangents = true;
|
||||
|
||||
},
|
||||
|
||||
computeBoundingBox: function () {
|
||||
|
||||
if ( this.vertices.length > 0 ) {
|
||||
|
||||
@@ -12,6 +12,8 @@ THREE.Vertex = function ( position, normal ) {
|
||||
this.normalWorld = new THREE.Vector3();
|
||||
this.normalScreen = new THREE.Vector3();
|
||||
|
||||
this.tangent = new THREE.Vector4();
|
||||
|
||||
this.__visible = true;
|
||||
|
||||
}
|
||||
|
||||
@@ -62,6 +62,201 @@ var ShaderUtils = {
|
||||
"}"
|
||||
].join("\n")
|
||||
|
||||
},
|
||||
|
||||
'normal' : {
|
||||
|
||||
uniforms: {
|
||||
|
||||
"tNormal": { type: "t", value: 2, texture: null },
|
||||
"tAO": { type: "t", value: 3, texture: null },
|
||||
|
||||
"tDisplacement": { type: "t", value: 4, texture: null },
|
||||
"uDisplacementBias": { type: "f", value: -0.5 },
|
||||
"uDisplacementScale":{ type: "f", value: 2.5 },
|
||||
|
||||
"uPointLightPos": { type: "v3", value: new THREE.Vector3() },
|
||||
"uPointLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
|
||||
|
||||
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
|
||||
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
|
||||
|
||||
"uAmbientLightColor":{ type: "c", value: new THREE.Color( 0x050505 ) },
|
||||
|
||||
"uDiffuseColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
|
||||
"uSpecularColor": { type: "c", value: new THREE.Color( 0x111111 ) },
|
||||
"uAmbientColor": { type: "c", value: new THREE.Color( 0x050505 ) },
|
||||
"uShininess": { type: "f", value: 30 }
|
||||
|
||||
},
|
||||
|
||||
fragment_shader: [
|
||||
|
||||
"uniform vec3 uDirLightPos;",
|
||||
"uniform vec3 uDirLightColor;",
|
||||
|
||||
"uniform vec3 uPointLightPos;",
|
||||
"uniform vec3 uPointLightColor;",
|
||||
|
||||
"uniform vec3 uAmbientColor;",
|
||||
"uniform vec3 uDiffuseColor;",
|
||||
"uniform vec3 uSpecularColor;",
|
||||
"uniform float uShininess;",
|
||||
|
||||
"uniform sampler2D tNormal;",
|
||||
"uniform sampler2D tAO;",
|
||||
|
||||
"varying vec3 vTangent;",
|
||||
"varying vec3 vBinormal;",
|
||||
"varying vec3 vNormal;",
|
||||
"varying vec2 vUv;",
|
||||
|
||||
"varying vec3 vLightWeighting;",
|
||||
"varying vec3 vPointLightVector;",
|
||||
"varying vec3 vViewPosition;",
|
||||
|
||||
"void main() {",
|
||||
|
||||
"vec3 normalTex = normalize( texture2D( tNormal, vUv ).xyz * 2.0 - 1.0 );",
|
||||
"vec3 aoTex = texture2D( tAO, vUv ).xyz;",
|
||||
|
||||
"mat3 tsb = mat3( vTangent, vBinormal, vNormal );",
|
||||
"vec3 finalNormal = tsb * normalTex;",
|
||||
|
||||
"vec3 normal = normalize( finalNormal );",
|
||||
"vec3 viewPosition = normalize( vViewPosition );",
|
||||
|
||||
// point light
|
||||
|
||||
"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );",
|
||||
"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );",
|
||||
|
||||
"vec3 pointVector = normalize( vPointLightVector );",
|
||||
"vec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );",
|
||||
|
||||
"float pointDotNormalHalf = dot( normal, pointHalfVector );",
|
||||
"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
|
||||
|
||||
"float pointSpecularWeight = 0.0;",
|
||||
"if ( pointDotNormalHalf >= 0.0 )",
|
||||
"pointSpecularWeight = pow( pointDotNormalHalf, uShininess );",
|
||||
|
||||
"pointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;",
|
||||
"pointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;",
|
||||
|
||||
// directional light
|
||||
|
||||
"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );",
|
||||
"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );",
|
||||
|
||||
"vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );",
|
||||
|
||||
"vec3 dirVector = normalize( lDirection.xyz );",
|
||||
"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );",
|
||||
|
||||
"float dirDotNormalHalf = dot( normal, dirHalfVector );",
|
||||
"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
|
||||
|
||||
"float dirSpecularWeight = 0.0;",
|
||||
"if ( dirDotNormalHalf >= 0.0 )",
|
||||
"dirSpecularWeight = pow( dirDotNormalHalf, uShininess );",
|
||||
|
||||
"dirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;",
|
||||
"dirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;",
|
||||
|
||||
// all lights contribution summation
|
||||
|
||||
"vec4 totalLight = vec4( uAmbientColor, 1.0 );",
|
||||
"totalLight += dirDiffuse + dirSpecular;",
|
||||
"totalLight += pointDiffuse + pointSpecular;",
|
||||
|
||||
"gl_FragColor = vec4( totalLight.xyz * vLightWeighting * aoTex, 1.0 );",
|
||||
|
||||
"}"
|
||||
].join("\n"),
|
||||
|
||||
vertex_shader: [
|
||||
|
||||
"attribute vec4 tangent;",
|
||||
|
||||
"uniform vec3 uDirLightPos;",
|
||||
"uniform vec3 uDirLightColor;",
|
||||
|
||||
"uniform vec3 uPointLightPos;",
|
||||
"uniform vec3 uPointLightColor;",
|
||||
|
||||
"uniform vec3 uAmbientLightColor;",
|
||||
|
||||
"#ifdef VERTEX_TEXTURES",
|
||||
|
||||
"uniform sampler2D tDisplacement;",
|
||||
"uniform float uDisplacementScale;",
|
||||
"uniform float uDisplacementBias;",
|
||||
|
||||
"#endif",
|
||||
|
||||
"varying vec3 vTangent;",
|
||||
"varying vec3 vBinormal;",
|
||||
"varying vec3 vNormal;",
|
||||
"varying vec2 vUv;",
|
||||
|
||||
"varying vec3 vLightWeighting;",
|
||||
"varying vec3 vPointLightVector;",
|
||||
"varying vec3 vViewPosition;",
|
||||
|
||||
"void main() {",
|
||||
|
||||
"vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
|
||||
"vViewPosition = cameraPosition - mPosition.xyz;",
|
||||
|
||||
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
|
||||
"vNormal = normalize( normalMatrix * normal );",
|
||||
|
||||
// tangent and binormal vectors
|
||||
|
||||
"vTangent = normalize( normalMatrix * tangent.xyz );",
|
||||
|
||||
"vBinormal = cross( vNormal, vTangent ) * tangent.w;",
|
||||
"vBinormal = normalize( vBinormal );",
|
||||
|
||||
"vUv = uv;",
|
||||
|
||||
// ambient light
|
||||
|
||||
"vLightWeighting = uAmbientLightColor;",
|
||||
|
||||
// point light
|
||||
|
||||
"vec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );",
|
||||
"vPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );",
|
||||
"float pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );",
|
||||
"vLightWeighting += uPointLightColor * pointLightWeighting;",
|
||||
|
||||
// directional light
|
||||
|
||||
"vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );",
|
||||
"float directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );",
|
||||
"vLightWeighting += uDirLightColor * directionalLightWeighting;",
|
||||
|
||||
// displacement mapping
|
||||
|
||||
"#ifdef VERTEX_TEXTURES",
|
||||
|
||||
"vec3 dv = texture2D( tDisplacement, uv ).xyz;",
|
||||
"float df = uDisplacementScale * dv.x + uDisplacementBias;",
|
||||
"vec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;",
|
||||
"gl_Position = projectionMatrix * displacedPosition;",
|
||||
|
||||
"#else",
|
||||
|
||||
"gl_Position = projectionMatrix * mvPosition;",
|
||||
|
||||
"#endif",
|
||||
|
||||
"}"
|
||||
|
||||
].join("\n")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -159,13 +159,14 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
|
||||
this.createBuffers = function ( object, g ) {
|
||||
|
||||
var f, fl, fi, face, vertexNormals, normal, uv, v1, v2, v3, v4, m, ml, i,
|
||||
var f, fl, fi, face, vertexNormals, normal, uv, v1, v2, v3, v4, t1, t2, t3, t4, m, ml, i,
|
||||
|
||||
faceArray = [],
|
||||
lineArray = [],
|
||||
|
||||
vertexArray = [],
|
||||
normalArray = [],
|
||||
tangentArray = [],
|
||||
uvArray = [],
|
||||
|
||||
vertexIndex = 0,
|
||||
@@ -193,8 +194,21 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
vertexArray.push( v2.x, v2.y, v2.z );
|
||||
vertexArray.push( v3.x, v3.y, v3.z );
|
||||
|
||||
if ( object.geometry.hasTangents ) {
|
||||
|
||||
t1 = object.geometry.vertices[ face.a ].tangent;
|
||||
t2 = object.geometry.vertices[ face.b ].tangent;
|
||||
t3 = object.geometry.vertices[ face.c ].tangent;
|
||||
|
||||
tangentArray.push( t1.x, t1.y, t1.z, t1.w );
|
||||
tangentArray.push( t2.x, t2.y, t2.z, t2.w );
|
||||
tangentArray.push( t3.x, t3.y, t3.z, t3.w );
|
||||
|
||||
}
|
||||
|
||||
if ( vertexNormals.length == 3 && needsSmoothNormals ) {
|
||||
|
||||
|
||||
for ( i = 0; i < 3; i ++ ) {
|
||||
|
||||
normalArray.push( vertexNormals[ i ].x, vertexNormals[ i ].y, vertexNormals[ i ].z );
|
||||
@@ -242,15 +256,29 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
vertexArray.push( v2.x, v2.y, v2.z );
|
||||
vertexArray.push( v3.x, v3.y, v3.z );
|
||||
vertexArray.push( v4.x, v4.y, v4.z );
|
||||
|
||||
if ( object.geometry.hasTangents ) {
|
||||
|
||||
t1 = object.geometry.vertices[ face.a ].tangent;
|
||||
t2 = object.geometry.vertices[ face.b ].tangent;
|
||||
t3 = object.geometry.vertices[ face.c ].tangent;
|
||||
t4 = object.geometry.vertices[ face.d ].tangent;
|
||||
|
||||
tangentArray.push( t1.x, t1.y, t1.z, t1.w );
|
||||
tangentArray.push( t2.x, t2.y, t2.z, t2.w );
|
||||
tangentArray.push( t3.x, t3.y, t3.z, t3.w );
|
||||
tangentArray.push( t4.x, t4.y, t4.z, t4.w );
|
||||
|
||||
}
|
||||
|
||||
if ( vertexNormals.length == 4 && needsSmoothNormals ) {
|
||||
|
||||
|
||||
for ( i = 0; i < 4; i ++ ) {
|
||||
|
||||
normalArray.push( vertexNormals[ i ].x, vertexNormals[ i ].y, vertexNormals[ i ].z );
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
for ( i = 0; i < 4; i ++ ) {
|
||||
@@ -302,6 +330,14 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer );
|
||||
_gl.bufferData( _gl.ARRAY_BUFFER, new Float32Array( normalArray ), _gl.STATIC_DRAW );
|
||||
|
||||
if ( object.geometry.hasTangents ) {
|
||||
|
||||
geometryChunk.__webGLTangentBuffer = _gl.createBuffer();
|
||||
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLTangentBuffer );
|
||||
_gl.bufferData( _gl.ARRAY_BUFFER, new Float32Array( tangentArray ), _gl.STATIC_DRAW );
|
||||
|
||||
}
|
||||
|
||||
if ( uvArray.length > 0 ) {
|
||||
|
||||
geometryChunk.__webGLUVBuffer = _gl.createBuffer();
|
||||
@@ -346,7 +382,7 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
|
||||
}
|
||||
cacheUniformLocations( material.program, identifiers );
|
||||
cacheAttributeLocations( material.program, [ "position", "normal", "uv" ] );
|
||||
cacheAttributeLocations( material.program, [ "position", "normal", "uv", "tangent" ] );
|
||||
|
||||
}
|
||||
|
||||
@@ -374,7 +410,6 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
this.loadCamera( program, camera );
|
||||
this.loadMatrices( program );
|
||||
|
||||
|
||||
if ( material instanceof THREE.MeshShaderMaterial ) {
|
||||
|
||||
mWireframe = material.wireframe;
|
||||
@@ -507,6 +542,15 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer );
|
||||
_gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
|
||||
|
||||
// tangents
|
||||
|
||||
if ( attributes.tangent >= 0 ) {
|
||||
|
||||
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLTangentBuffer );
|
||||
_gl.vertexAttribPointer( attributes.tangent, 4, _gl.FLOAT, false, 0, 0 );
|
||||
|
||||
}
|
||||
|
||||
// uvs
|
||||
|
||||
if ( attributes.uv >= 0 ) {
|
||||
@@ -828,6 +872,19 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
|
||||
};
|
||||
|
||||
this.supportsVertexTextures = function() {
|
||||
|
||||
return maxVertexTextures() > 0;
|
||||
|
||||
};
|
||||
|
||||
function maxVertexTextures() {
|
||||
|
||||
return _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
|
||||
|
||||
};
|
||||
|
||||
|
||||
function initGL() {
|
||||
|
||||
try {
|
||||
@@ -940,7 +997,7 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
|
||||
"} else if ( material == 4 ) { ",
|
||||
|
||||
"gl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );",
|
||||
"gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );",
|
||||
|
||||
// Depth
|
||||
|
||||
@@ -1184,6 +1241,8 @@ THREE.WebGLRenderer = function ( scene ) {
|
||||
].join("\n"),
|
||||
|
||||
prefix_vertex = [
|
||||
maxVertexTextures() > 0 ? "#define VERTEX_TEXTURES" : "",
|
||||
|
||||
"uniform mat4 objectMatrix;",
|
||||
"uniform mat4 modelViewMatrix;",
|
||||
"uniform mat4 projectionMatrix;",
|
||||
|
||||
Reference in New Issue
Block a user