Browse Source

Ray.intersectObject now also sorts. Fixes #1837.

Mr.doob 13 years ago
parent
commit
201c92a8dd
1 changed files with 9 additions and 1 deletions
  1. 9 1
      src/core/Ray.js

+ 9 - 1
src/core/Ray.js

@@ -26,6 +26,12 @@ THREE.Ray = function ( origin, direction ) {
 	var vector = new THREE.Vector3();
 	var normal = new THREE.Vector3();
 	var intersectPoint = new THREE.Vector3()
+	
+	var descSort = function ( a, b ) {
+	
+			return a.distance - b.distance;
+			
+	};
 
 	this.intersectObject = function ( object ) {
 
@@ -157,6 +163,8 @@ THREE.Ray = function ( origin, direction ) {
 
 		}
 
+		intersects.sort( descSort );
+
 		return intersects;
 
 	}
@@ -171,7 +179,7 @@ THREE.Ray = function ( origin, direction ) {
 
 		}
 
-		intersects.sort( function ( a, b ) { return a.distance - b.distance; } );
+		intersects.sort( descSort );
 
 		return intersects;