Browse Source

Moved Raycaster's Sprite code to Sprite.raycast(). See #3492.

Mr.doob 11 years ago
parent
commit
8ae3dae6ae
2 changed files with 29 additions and 22 deletions
  1. 1 19
      src/core/Raycaster.js
  2. 28 3
      src/objects/Sprite.js

+ 1 - 19
src/core/Raycaster.js

@@ -46,25 +46,7 @@
 
 
 		if ( object instanceof THREE.Sprite ) {
 		if ( object instanceof THREE.Sprite ) {
 
 
-			matrixPosition.setFromMatrixPosition( object.matrixWorld );
-			
-			var distance = raycaster.ray.distanceToPoint( matrixPosition );
-
-			if ( distance > object.scale.x ) {
-
-				return intersects;
-
-			}
-
-			intersects.push( {
-
-				distance: distance,
-				point: object.position,
-				face: null,
-				object: object
-
-			} );
-
+			object.raycast( raycaster, intersects );
 
 
 		} else if ( object instanceof THREE.PointCloud ) {
 		} else if ( object instanceof THREE.PointCloud ) {
 		
 		

+ 28 - 3
src/objects/Sprite.js

@@ -23,9 +23,34 @@ THREE.Sprite = ( function () {
 
 
 THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
 THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
 
 
-/*
- * Custom update matrix
- */
+THREE.Sprite.prototype.raycast = ( function () {
+
+	var matrixPosition = new THREE.Vector3();
+
+	return function ( raycaster, intersects ) {
+
+		matrixPosition.setFromMatrixPosition( this.matrixWorld );
+			
+		var distance = raycaster.ray.distanceToPoint( matrixPosition );
+
+		if ( distance > this.scale.x ) {
+
+			return intersects;
+
+		}
+
+		intersects.push( {
+
+			distance: distance,
+			point: this.position,
+			face: null,
+			object: this
+
+		} );
+		
+	};
+
+} )();
 
 
 THREE.Sprite.prototype.updateMatrix = function () {
 THREE.Sprite.prototype.updateMatrix = function () {