|
@@ -13,7 +13,7 @@ THREE.Vector4=function(b,c,d,e){this.set(b||0,c||0,d||0,e||1)};
|
|
|
THREE.Vector4.prototype={set:function(b,c,d,e){this.x=b;this.y=c;this.z=d;this.w=e;return this},copy:function(b){return this.set(b.x,b.y,b.z,b.w||1)},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(b,c){this.x=b.x+c.x;this.y=b.y+c.y;this.z=b.z+c.z;this.w=b.w+c.w;return this},addSelf:function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z;this.w+=b.w;return this},sub:function(b,c){this.x=b.x-c.x;this.y=b.y-c.y;this.z=b.z-c.z;this.w=b.w-c.w;return this},subSelf:function(b){this.x-=
|
|
|
b.x;this.y-=b.y;this.z-=b.z;this.w-=b.w;return this},multiplyScalar:function(b){this.x*=b;this.y*=b;this.z*=b;this.w*=b;return this},divideScalar:function(b){b?(this.x/=b,this.y/=b,this.z/=b,this.w/=b):this.set(0,0,0,1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(b){return this.x*b.x+this.y*b.y+this.z*b.z+this.w*b.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},
|
|
|
setLength:function(b){return this.normalize().multiplyScalar(b)},lerpSelf:function(b,c){this.x+=(b.x-this.x)*c;this.y+=(b.y-this.y)*c;this.z+=(b.z-this.z)*c;this.w+=(b.w-this.w)*c;return this}};THREE.Ray=function(b,c){this.origin=b||new THREE.Vector3;this.direction=c||new THREE.Vector3};
|
|
|
-THREE.Ray.prototype={intersectScene:function(b){return this.intersectObjects(b.objects)},intersectObjects:function(b){var c,d,e=[];c=0;for(d=b.length;c<d;c++)e=e.concat(this.intersectObject(b[c]));e.sort(function(b,d){return b.distance-d.distance});return e},intersectObject:function(b){function c(b,d,c){var e;e=c.position.clone().subSelf(b).dot(d);b=b.clone().addSelf(d.clone().multiplyScalar(e));return c.position.distanceTo(b)}function d(b,d,c,e){var e=e.clone().subSelf(d),c=c.clone().subSelf(d),
|
|
|
+THREE.Ray.prototype={intersectScene:function(b){return this.intersectObjects(b.objects)},intersectObjects:function(b){var c,d,e=[];c=0;for(d=b.length;c<d;c++)e=e.concat(this.intersectObject(b[c]));e.sort(function(b,d){return b.distance-d.distance});return e},intersectObject:function(b){function c(b,d,c){var e,c=c.matrixWorld.getPosition();e=c.clone().subSelf(b).dot(d);b=b.clone().addSelf(d.clone().multiplyScalar(e));return c.distanceTo(b)}function d(b,d,c,e){var e=e.clone().subSelf(d),c=c.clone().subSelf(d),
|
|
|
f=b.clone().subSelf(d),b=e.dot(e),d=e.dot(c),e=e.dot(f),g=c.dot(c),c=c.dot(f),f=1/(b*g-d*d),g=(g*e-d*c)*f,b=(b*c-d*e)*f;return g>0&&b>0&&g+b<1}if(b instanceof THREE.Particle){var e=c(this.origin,this.direction,b);if(!e||e>b.scale.x)return[];return[{distance:e,point:b.position,face:null,object:b}]}else if(b instanceof THREE.Mesh){e=c(this.origin,this.direction,b);if(!e||e>b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)))return[];var f,g,j,k,m,o,p,t,n,u,v=b.geometry,
|
|
|
y=v.vertices,B=[],e=0;for(f=v.faces.length;e<f;e++)if(g=v.faces[e],n=this.origin.clone(),u=this.direction.clone(),o=b.matrixWorld,j=o.multiplyVector3(y[g.a].position.clone()),k=o.multiplyVector3(y[g.b].position.clone()),m=o.multiplyVector3(y[g.c].position.clone()),o=g instanceof THREE.Face4?o.multiplyVector3(y[g.d].position.clone()):null,p=b.matrixRotationWorld.multiplyVector3(g.normal.clone()),t=u.dot(p),b.doubleSided||(b.flipSided?t>0:t<0))if(p=p.dot((new THREE.Vector3).sub(j,n))/t,n=n.addSelf(u.multiplyScalar(p)),
|
|
|
g instanceof THREE.Face3)d(n,j,k,m)&&(g={distance:this.origin.distanceTo(n),point:n,face:g,object:b},B.push(g));else if(g instanceof THREE.Face4&&(d(n,j,k,o)||d(n,k,m,o)))g={distance:this.origin.distanceTo(n),point:n,face:g,object:b},B.push(g);return B}else return[]}};
|