Selaa lähdekoodia

remove GC from Ray.distanceToPoint

Ben Houston 12 vuotta sitten
vanhempi
commit
b83d79b759
1 muutettua tiedostoa jossa 3 lisäystä ja 3 poistoa
  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 );
 
 	},