提交 3be2cdae 编写于 作者: M Mr.doob

Better Rectangle.intersects() formula.

上级 d906f301
此差异已折叠。
......@@ -23,7 +23,7 @@ b.copy(this.direction),H=i.matrixWorld,n=H.multiplyVector3(n.copy(h.centroid)).s
e,f,g)&&(h={distance:a.distanceTo(l),point:l.clone(),face:h,object:i},o.push(h));else if(h instanceof THREE.Face4&&(d(l,e,f,j)||d(l,f,g,j)))h={distance:a.distanceTo(l),point:l.clone(),face:h,object:i},o.push(h)}return o};var h=new THREE.Vector3,m=new THREE.Vector3,o=new THREE.Vector3,p,i,q,F,x,I,G,r,C,y,D};
THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,j=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,l,h){j=!1;b=f;c=g;d=l;e=h;a()};this.addPoint=function(f,g){j?(j=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
function(f,g,l,h,m,o){j?(j=!1,b=f<l?f<m?f:m:l<m?l:m,c=g<h?g<o?g:o:h<o?h:o,d=f>l?f>m?f:m:l>m?l:m,e=g>h?g>o?g:o:h>o?h:o):(b=f<l?f<m?f<b?f:b:m<b?m:b:l<m?l<b?l:b:m<b?m:b,c=g<h?g<o?g<c?g:c:o<c?o:c:h<o?h<c?h:c:o<c?o:c,d=f>l?f>m?f>d?f:d:m>d?m:d:l>m?l>d?l:d:m>d?m:d,e=g>h?g>o?g>e?g:e:o>e?o:e:h>o?h>e?h:e:o>e?o:e);a()};this.addRectangle=function(f){j?(j=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){j=!0;e=d=c=b=0;a()};this.isEmpty=function(){return j}};
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){if(d<a.getLeft())return!1;if(b>a.getRight())return!1;if(e<a.getTop())return!1;if(c>a.getBottom())return!1;return!0};this.empty=function(){j=!0;e=d=c=b=0;a()};this.isEmpty=function(){return j}};
THREE.Math={clamp:function(a,b,c){return a<b?b:a>c?c:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())}};THREE.Matrix3=function(){this.m=[]};
THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
THREE.Matrix4=function(a,b,c,d,e,f,g,j,n,k,l,h,m,o,p,i){this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,j||0,n||0,k||0,l!==void 0?l:1,h||0,m||0,o||0,p||0,i!==void 0?i:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
......@@ -76,7 +76,7 @@ this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRo
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b=
this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,j=a.z,a=a.w;this.x=b*a+e*f+c*j-d*g;this.y=c*a+e*g+d*f-b*j;this.z=d*a+e*j+b*g-c*f;this.w=e*a-b*f-c*g-d*j;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,j=this.z,n=this.w,k=n*c+g*e-j*d,l=n*d+j*c-f*e,h=n*e+f*d-g*c,c=-f*
c-g*d-j*e;b.x=k*n+c*-f+l*-j-h*-g;b.y=l*n+c*-g+h*-f-k*-j;b.z=h*n+c*-j+k*-g-l*-f;return b}};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;e<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.0010)return c.w=0.5*(a.w+b.w),c.x=0.5*(a.x+b.x),c.y=0.5*(a.y+b.y),c.z=0.5*(a.z+b.z),c;b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;e<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.001)return c.w=0.5*(a.w+b.w),c.x=0.5*(a.x+b.x),c.y=0.5*(a.y+b.y),c.z=0.5*(a.z+b.z),c;b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3};
THREE.Face4=function(a,b,c,d,e,f,g){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
......
......@@ -23,7 +23,7 @@ b.copy(this.direction),q=k.matrixWorld,l=q.multiplyVector3(l.copy(m.centroid)).s
e,f,g)&&(m={distance:a.distanceTo(j),point:j.clone(),face:m,object:k},n.push(m));else if(m instanceof THREE.Face4&&(d(j,e,f,h)||d(j,f,g,h)))m={distance:a.distanceTo(j),point:j.clone(),face:m,object:k},n.push(m)}return n};var k=new THREE.Vector3,m=new THREE.Vector3,n=new THREE.Vector3,p,o,r,C,t,B,D,q,y,u,w};
THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,j,k){h=!1;b=f;c=g;d=j;e=k;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
function(f,g,j,k,m,n){h?(h=!1,b=f<j?f<m?f:m:j<m?j:m,c=g<k?g<n?g:n:k<n?k:n,d=f>j?f>m?f:m:j>m?j:m,e=g>k?g>n?g:n:k>n?k:n):(b=f<j?f<m?f<b?f:b:m<b?m:b:j<m?j<b?j:b:m<b?m:b,c=g<k?g<n?g<c?g:c:n<c?n:c:k<n?k<c?k:c:n<c?n:c,d=f>j?f>m?f>d?f:d:m>d?m:d:j>m?j>d?j:d:m>d?m:d,e=g>k?g>n?g>e?g:e:n>e?n:e:k>n?k>e?k:e:n>e?n:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){if(d<a.getLeft())return!1;if(b>a.getRight())return!1;if(e<a.getTop())return!1;if(c>a.getBottom())return!1;return!0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
THREE.Math={clamp:function(a,b,c){return a<b?b:a>c?c:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())}};THREE.Matrix3=function(){this.m=[]};
THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
THREE.Matrix4=function(a,b,c,d,e,f,g,h,l,i,j,k,m,n,p,o){this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,h||0,l||0,i||0,j!==void 0?j:1,k||0,m||0,n||0,p||0,o!==void 0?o:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
......@@ -76,7 +76,7 @@ this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRo
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b=
this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,h=a.z,a=a.w;this.x=b*a+e*f+c*h-d*g;this.y=c*a+e*g+d*f-b*h;this.z=d*a+e*h+b*g-c*f;this.w=e*a-b*f-c*g-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,h=this.z,l=this.w,i=l*c+g*e-h*d,j=l*d+h*c-f*e,k=l*e+f*d-g*c,c=-f*
c-g*d-h*e;b.x=i*l+c*-f+j*-h-k*-g;b.y=j*l+c*-g+k*-f-i*-h;b.z=k*l+c*-h+i*-g-j*-f;return b}};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;e<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.0010)return c.w=0.5*(a.w+b.w),c.x=0.5*(a.x+b.x),c.y=0.5*(a.y+b.y),c.z=0.5*(a.z+b.z),c;b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;e<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.001)return c.w=0.5*(a.w+b.w),c.x=0.5*(a.x+b.x),c.y=0.5*(a.y+b.y),c.z=0.5*(a.z+b.z),c;b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3};
THREE.Face4=function(a,b,c,d,e,f,g){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
......
此差异已折叠。
......@@ -23,7 +23,7 @@ b.copy(this.direction),t=j.matrixWorld,l=t.multiplyVector3(l.copy(m.centroid)).s
e,f,g)&&(m={distance:a.distanceTo(k),point:k.clone(),face:m,object:j},n.push(m));else if(m instanceof THREE.Face4&&(d(k,e,f,h)||d(k,f,g,h)))m={distance:a.distanceTo(k),point:k.clone(),face:m,object:j},n.push(m)}return n};var j=new THREE.Vector3,n=new THREE.Vector3,m=new THREE.Vector3,o,p,u,F,v,D,s,t,B,x,y};
THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,k,j){h=!1;b=f;c=g;d=k;e=j;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=b<f?b:f,c=c<g?c:g,d=d>f?d:f,e=e>g?e:g);a()};this.add3Points=
function(f,g,k,j,n,m){h?(h=!1,b=f<k?f<n?f:n:k<n?k:n,c=g<j?g<m?g:m:j<m?j:m,d=f>k?f>n?f:n:k>n?k:n,e=g>j?g>m?g:m:j>m?j:m):(b=f<k?f<n?f<b?f:b:n<b?n:b:k<n?k<b?k:b:n<b?n:b,c=g<j?g<m?g<c?g:c:m<c?m:c:j<m?j<c?j:c:m<c?m:c,d=f>k?f>n?f>d?f:d:n>d?n:d:k>n?k>d?k:d:n>d?n:d,e=g>j?g>m?g>e?g:e:m>e?m:e:j>m?j>e?j:e:m>e?m:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=b<f.getLeft()?b:f.getLeft(),c=c<f.getTop()?c:f.getTop(),d=d>f.getRight()?d:f.getRight(),e=e>
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){return Math.min(d,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(e,a.getBottom())-Math.max(c,a.getTop())>=0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){if(d<a.getLeft())return!1;if(b>a.getRight())return!1;if(e<a.getTop())return!1;if(c>a.getBottom())return!1;return!0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
THREE.Math={clamp:function(a,b,c){return a<b?b:a>c?c:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())}};THREE.Matrix3=function(){this.m=[]};
THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
THREE.Matrix4=function(a,b,c,d,e,f,g,h,l,i,k,j,n,m,o,p){this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,h||0,l||0,i||0,k!==void 0?k:1,j||0,n||0,m||0,o||0,p!==void 0?p:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
......@@ -76,7 +76,7 @@ this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRo
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b=
this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,h=a.z,a=a.w;this.x=b*a+e*f+c*h-d*g;this.y=c*a+e*g+d*f-b*h;this.z=d*a+e*h+b*g-c*f;this.w=e*a-b*f-c*g-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,h=this.z,l=this.w,i=l*c+g*e-h*d,k=l*d+h*c-f*e,j=l*e+f*d-g*c,c=-f*
c-g*d-h*e;b.x=i*l+c*-f+k*-h-j*-g;b.y=k*l+c*-g+j*-f-i*-h;b.z=j*l+c*-h+i*-g-k*-f;return b}};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;e<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.0010)return c.w=0.5*(a.w+b.w),c.x=0.5*(a.x+b.x),c.y=0.5*(a.y+b.y),c.z=0.5*(a.z+b.z),c;b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;e<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.001)return c.w=0.5*(a.w+b.w),c.x=0.5*(a.x+b.x),c.y=0.5*(a.y+b.y),c.z=0.5*(a.z+b.z),c;b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3};
THREE.Face4=function(a,b,c,d,e,f,g){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
......
......@@ -23,7 +23,7 @@ b.copy(this.direction),I=n.matrixWorld,l=I.multiplyVector3(l.copy(w.centroid)).s
f,g,h)&&(w={distance:a.distanceTo(j),point:j.clone(),face:w,object:n},p.push(w));else if(w instanceof THREE.Face4&&(c(j,f,g,i)||c(j,g,h,i)))w={distance:a.distanceTo(j),point:j.clone(),face:w,object:n},p.push(w)}return p};var p=new THREE.Vector3,s=new THREE.Vector3,w=new THREE.Vector3,n,E,y,J,P,Q,V,C,D,N,O};
THREE.Rectangle=function(){function a(){g=c-b;h=f-d}var b,d,c,f,g,h,i=!0;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return g};this.getHeight=function(){return h};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return c};this.getBottom=function(){return f};this.set=function(g,h,j,p){i=!1;b=g;d=h;c=j;f=p;a()};this.addPoint=function(g,h){i?(i=!1,b=g,d=h,c=g,f=h):(b=b<g?b:g,d=d<h?d:h,c=c>g?c:g,f=f>h?f:h);a()};this.add3Points=
function(g,h,j,p,s,w){i?(i=!1,b=g<j?g<s?g:s:j<s?j:s,d=h<p?h<w?h:w:p<w?p:w,c=g>j?g>s?g:s:j>s?j:s,f=h>p?h>w?h:w:p>w?p:w):(b=g<j?g<s?g<b?g:b:s<b?s:b:j<s?j<b?j:b:s<b?s:b,d=h<p?h<w?h<d?h:d:w<d?w:d:p<w?p<d?p:d:w<d?w:d,c=g>j?g>s?g>c?g:c:s>c?s:c:j>s?j>c?j:c:s>c?s:c,f=h>p?h>w?h>f?h:f:w>f?w:f:p>w?p>f?p:f:w>f?w:f);a()};this.addRectangle=function(g){i?(i=!1,b=g.getLeft(),d=g.getTop(),c=g.getRight(),f=g.getBottom()):(b=b<g.getLeft()?b:g.getLeft(),d=d<g.getTop()?d:g.getTop(),c=c>g.getRight()?c:g.getRight(),f=f>
g.getBottom()?f:g.getBottom());a()};this.inflate=function(g){b-=g;d-=g;c+=g;f+=g;a()};this.minSelf=function(g){b=b>g.getLeft()?b:g.getLeft();d=d>g.getTop()?d:g.getTop();c=c<g.getRight()?c:g.getRight();f=f<g.getBottom()?f:g.getBottom();a()};this.intersects=function(a){return Math.min(c,a.getRight())-Math.max(b,a.getLeft())>=0&&Math.min(f,a.getBottom())-Math.max(d,a.getTop())>=0};this.empty=function(){i=!0;f=c=d=b=0;a()};this.isEmpty=function(){return i}};
g.getBottom()?f:g.getBottom());a()};this.inflate=function(g){b-=g;d-=g;c+=g;f+=g;a()};this.minSelf=function(g){b=b>g.getLeft()?b:g.getLeft();d=d>g.getTop()?d:g.getTop();c=c<g.getRight()?c:g.getRight();f=f<g.getBottom()?f:g.getBottom();a()};this.intersects=function(a){if(c<a.getLeft())return!1;if(b>a.getRight())return!1;if(f<a.getTop())return!1;if(d>a.getBottom())return!1;return!0};this.empty=function(){i=!0;f=c=d=b=0;a()};this.isEmpty=function(){return i}};
THREE.Math={clamp:function(a,b,d){return a<b?b:a>d?d:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,d,c,f){return c+(a-b)*(f-c)/(d-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())}};THREE.Matrix3=function(){this.m=[]};
THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};
THREE.Matrix4=function(a,b,d,c,f,g,h,i,l,k,j,p,s,w,n,E){this.set(a!==void 0?a:1,b||0,d||0,c||0,f||0,g!==void 0?g:1,h||0,i||0,l||0,k||0,j!==void 0?j:1,p||0,s||0,w||0,n||0,E!==void 0?E:1);this.flat=Array(16);this.m33=new THREE.Matrix3};
......@@ -76,7 +76,7 @@ this.x=a.x*c;this.y=a.y*c;this.z=a.z*c;this.w=Math.cos(d);return this},setFromRo
this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b=
this.x,d=this.y,c=this.z,f=this.w,g=a.x,h=a.y,i=a.z,a=a.w;this.x=b*a+f*g+d*i-c*h;this.y=d*a+f*h+c*g-b*i;this.z=c*a+f*i+b*h-d*g;this.w=f*a-b*g-d*h-c*i;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var d=a.x,c=a.y,f=a.z,g=this.x,h=this.y,i=this.z,l=this.w,k=l*d+h*f-i*c,j=l*c+i*d-g*f,p=l*f+g*c-h*d,d=-g*
d-h*c-i*f;b.x=k*l+d*-g+j*-i-p*-h;b.y=j*l+d*-h+p*-g-k*-i;b.z=p*l+d*-i+k*-h-j*-g;return b}};
THREE.Quaternion.slerp=function(a,b,d,c){var f=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;f<0?(d.w=-b.w,d.x=-b.x,d.y=-b.y,d.z=-b.z,f=-f):d.copy(b);if(Math.abs(f)>=1)return d.w=a.w,d.x=a.x,d.y=a.y,d.z=a.z,d;var g=Math.acos(f),f=Math.sqrt(1-f*f);if(Math.abs(f)<0.0010)return d.w=0.5*(a.w+b.w),d.x=0.5*(a.x+b.x),d.y=0.5*(a.y+b.y),d.z=0.5*(a.z+b.z),d;b=Math.sin((1-c)*g)/f;c=Math.sin(c*g)/f;d.w=a.w*b+d.w*c;d.x=a.x*b+d.x*c;d.y=a.y*b+d.y*c;d.z=a.z*b+d.z*c;return d};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
THREE.Quaternion.slerp=function(a,b,d,c){var f=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;f<0?(d.w=-b.w,d.x=-b.x,d.y=-b.y,d.z=-b.z,f=-f):d.copy(b);if(Math.abs(f)>=1)return d.w=a.w,d.x=a.x,d.y=a.y,d.z=a.z,d;var g=Math.acos(f),f=Math.sqrt(1-f*f);if(Math.abs(f)<0.001)return d.w=0.5*(a.w+b.w),d.x=0.5*(a.x+b.x),d.y=0.5*(a.y+b.y),d.z=0.5*(a.z+b.z),d;b=Math.sin((1-c)*g)/f;c=Math.sin(c*g)/f;d.w=a.w*b+d.w*c;d.x=a.x*b+d.x*c;d.y=a.y*b+d.y*c;d.z=a.z*b+d.z*c;return d};THREE.Vertex=function(a){this.position=a||new THREE.Vector3};
THREE.Face3=function(a,b,d,c,f,g){this.a=a;this.b=b;this.c=d;this.normal=c instanceof THREE.Vector3?c:new THREE.Vector3;this.vertexNormals=c instanceof Array?c:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};
THREE.Face4=function(a,b,d,c,f,g,h){this.a=a;this.b=b;this.c=d;this.d=c;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materialIndex=h;this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
......@@ -302,7 +302,7 @@ b.bindTexture(b.TEXTURE_2D,c.occlusionTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGB
"color");c.uniforms.scale=b.getUniformLocation(c.program,"scale");c.uniforms.rotation=b.getUniformLocation(c.program,"rotation");c.uniforms.screenPosition=b.getUniformLocation(c.program,"screenPosition");c.attributesEnabled=!1};this.render=function(a,g,h,i){var a=a.__webglFlares,l=a.length;if(l){var k=new THREE.Vector3,j=i/h,p=h*0.5,s=i*0.5,w=16/i,n=new THREE.Vector2(w*j,w),E=new THREE.Vector3(1,1,0),y=new THREE.Vector2(1,1),J=c.uniforms,w=c.attributes;b.useProgram(c.program);if(!c.attributesEnabled)b.enableVertexAttribArray(c.attributes.vertex),
b.enableVertexAttribArray(c.attributes.uv),c.attributesEnabled=!0;b.uniform1i(J.occlusionMap,0);b.uniform1i(J.map,1);b.bindBuffer(b.ARRAY_BUFFER,c.vertexBuffer);b.vertexAttribPointer(w.vertex,2,b.FLOAT,!1,16,0);b.vertexAttribPointer(w.uv,2,b.FLOAT,!1,16,8);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,c.elementBuffer);b.disable(b.CULL_FACE);b.depthMask(!1);var P,Q,V,C,D;for(P=0;P<l;P++)if(w=16/i,n.set(w*j,w),C=a[P],k.set(C.matrixWorld.n14,C.matrixWorld.n24,C.matrixWorld.n34),g.matrixWorldInverse.multiplyVector3(k),
g.projectionMatrix.multiplyVector3(k),E.copy(k),y.x=E.x*p+p,y.y=E.y*s+s,c.hasVertexTexture||y.x>0&&y.x<h&&y.y>0&&y.y<i){b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_2D,c.tempTexture);b.copyTexImage2D(b.TEXTURE_2D,0,b.RGB,y.x-8,y.y-8,16,16,0);b.uniform1i(J.renderType,0);b.uniform2f(J.scale,n.x,n.y);b.uniform3f(J.screenPosition,E.x,E.y,E.z);b.disable(b.BLEND);b.enable(b.DEPTH_TEST);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0);b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,c.occlusionTexture);
b.copyTexImage2D(b.TEXTURE_2D,0,b.RGBA,y.x-8,y.y-8,16,16,0);b.uniform1i(J.renderType,1);b.disable(b.DEPTH_TEST);b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_2D,c.tempTexture);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0);C.positionScreen.copy(E);C.customUpdateCallback?C.customUpdateCallback(C):C.updateLensFlares();b.uniform1i(J.renderType,2);b.enable(b.BLEND);Q=0;for(V=C.lensFlares.length;Q<V;Q++)if(D=C.lensFlares[Q],D.opacity>0.0010&&D.scale>0.0010)E.x=D.x,E.y=D.y,E.z=D.z,w=D.size*D.scale/
b.copyTexImage2D(b.TEXTURE_2D,0,b.RGBA,y.x-8,y.y-8,16,16,0);b.uniform1i(J.renderType,1);b.disable(b.DEPTH_TEST);b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_2D,c.tempTexture);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0);C.positionScreen.copy(E);C.customUpdateCallback?C.customUpdateCallback(C):C.updateLensFlares();b.uniform1i(J.renderType,2);b.enable(b.BLEND);Q=0;for(V=C.lensFlares.length;Q<V;Q++)if(D=C.lensFlares[Q],D.opacity>0.001&&D.scale>0.001)E.x=D.x,E.y=D.y,E.z=D.z,w=D.size*D.scale/
i,n.x=w*j,n.y=w,b.uniform3f(J.screenPosition,E.x,E.y,E.z),b.uniform2f(J.scale,n.x,n.y),b.uniform1f(J.rotation,D.rotation),b.uniform1f(J.opacity,D.opacity),b.uniform3f(J.color,D.color.r,D.color.g,D.color.b),d.setBlending(D.blending),d.setTexture(D.texture,1),b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(!0)}}};
THREE.ShadowMapPlugin=function(){var a,b,d,c,f,g=new THREE.Frustum,h=new THREE.Matrix4;this.shadowMatrix=[];this.shadowMap=[];this.init=function(f){a=f.context;b=f;var f=THREE.ShaderLib.depthRGBA,g=THREE.UniformsUtils.clone(f.uniforms);d=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,vertexShader:f.vertexShader,uniforms:g});c=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,vertexShader:f.vertexShader,uniforms:g,morphTargets:!0});d._shadowPass=!0;c._shadowPass=!0};this.render=
function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(i){var l,k,j,p,s,w,n,E,y=0,J=i.lights;f||(f=new THREE.PerspectiveCamera(b.shadowCameraFov,b.shadowMapWidth/b.shadowMapHeight,b.shadowCameraNear,b.shadowCameraFar));l=0;for(k=J.length;l<k;l++)if(n=J[l],n.castShadow&&n instanceof THREE.SpotLight){this.shadowMap[y]||(this.shadowMap[y]=new THREE.WebGLRenderTarget(b.shadowMapWidth,b.shadowMapHeight,{minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,
......
......@@ -165,8 +165,14 @@ THREE.Rectangle = function () {
this.intersects = function ( r ) {
return Math.min( _right, r.getRight() ) - Math.max( _left, r.getLeft() ) >= 0 &&
Math.min( _bottom, r.getBottom() ) - Math.max( _top, r.getTop() ) >= 0;
// http://gamemath.com/2011/09/detecting-whether-two-boxes-overlap/
if ( _right < r.getLeft() ) return false;
if ( _left > r.getRight() ) return false;
if ( _bottom < r.getTop() ) return false;
if ( _top > r.getBottom() ) return false;
return true;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册