提交 45fa8fff 编写于 作者: M Mr.doob

Ray.js: Now ignores objects behind origin and also faces behind origin (using the centroid).

上级 6e5d0490
因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -117,7 +117,7 @@
}
var radius = 600;
var radius = 100;
var theta = 0;
function render() {
......
......@@ -40,9 +40,9 @@ THREE.Ray.prototype = {
if ( object instanceof THREE.Particle ) {
var distance = distanceFromIntersection( this.origin, this.direction, object );
var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() );
if ( distance > object.scale.x ) {
if ( distance == null || distance > object.scale.x ) {
return [];
......@@ -61,9 +61,9 @@ THREE.Ray.prototype = {
// Checking boundingSphere
var distance = distanceFromIntersection( this.origin, this.direction, object );
var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() );
if ( distance > object.geometry.boundingSphere.radius * Math.max( object.scale.x, Math.max( object.scale.y, object.scale.z ) ) ) {
if ( distance == null || distance > object.geometry.boundingSphere.radius * Math.max( object.scale.x, Math.max( object.scale.y, object.scale.z ) ) ) {
return [];
......@@ -71,8 +71,9 @@ THREE.Ray.prototype = {
// Checking faces
var f, fl, face, a, b, c, d, normal,
dot, scalar,
var f, fl, face,
a, b, c, d, normal,
vector, dot, scalar,
origin, direction,
geometry = object.geometry,
vertices = geometry.vertices,
......@@ -89,6 +90,15 @@ THREE.Ray.prototype = {
objMatrix = object.matrixWorld;
// check if face.centroid is behind the origin
vector = objMatrix.multiplyVector3( face.centroid.clone() ).subSelf( origin );
dot = vector.dot( direction );
if ( dot < 0 ) continue;
//
a = objMatrix.multiplyVector3( vertices[ face.a ].position.clone() );
b = objMatrix.multiplyVector3( vertices[ face.b ].position.clone() );
c = objMatrix.multiplyVector3( vertices[ face.c ].position.clone() );
......@@ -142,6 +152,8 @@ THREE.Ray.prototype = {
}
intersects.sort( function ( a, b ) { return a.distance - b.distance; } );
return intersects;
} else {
......@@ -150,19 +162,18 @@ THREE.Ray.prototype = {
}
function distanceFromIntersection( origin, direction, object ) {
function distanceFromIntersection( origin, direction, position ) {
var vector, dot, intersect, distance,
position = object.matrixWorld.getPosition();
var vector, dot, intersect, distance;
vector = position.clone().subSelf( origin );
dot = vector.dot( direction );
if ( dot < 0 ) return null; // check if position behind origin.
intersect = origin.clone().addSelf( direction.clone().multiplyScalar( dot ) );
distance = position.distanceTo( intersect );
// TODO: Check if distance is negative (object behind camera).
return distance;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册