소스 검색

remove GC from Ray.distanceToPoint

Ben Houston 12 년 전
부모
커밋
b83d79b759
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      src/math/Ray.js

+ 3 - 3
src/math/Ray.js

@@ -57,10 +57,10 @@ THREE.Ray.prototype = {
 
 	distanceToPoint: function ( point ) {
 
-		// NOTE: this creates a THREE.VEctor3 internally via closestPointToPoint
-		// that is never returned, can be further GC optimized
+		var directionDistance = THREE.Ray.__v1.sub( point, this.origin ).dot( this.direction );		
+		THREE.Ray.__v1.copy( this.direction ).multiplyScalar( directionDistance ).addSelf( this.origin );
 
-		return this.closestPointToPoint( point ).distanceTo( point );
+		return THREE.Ray.__v1.distanceTo( point );
 
 	},