Browse Source

Revert "Improve Vector3 closure performance"

This reverts commit b0c0e3c789e7aa2fcc1b271eb5a39d6834a71bc9.
Joe Fox 8 years ago
parent
commit
49a71ce729
1 changed files with 26 additions and 8 deletions
  1. 26 8
      src/math/Vector3.js

+ 26 - 8
src/math/Vector3.js

@@ -234,7 +234,7 @@ Object.assign( Vector3.prototype, {
 
 	applyEuler: function () {
 
-		var quaternion = new Quaternion();
+		var quaternion;
 
 		return function applyEuler( euler ) {
 
@@ -244,6 +244,8 @@ Object.assign( Vector3.prototype, {
 
 			}
 
+			if ( quaternion === undefined ) quaternion = new Quaternion();
+
 			return this.applyQuaternion( quaternion.setFromEuler( euler ) );
 
 		};
@@ -252,10 +254,12 @@ Object.assign( Vector3.prototype, {
 
 	applyAxisAngle: function () {
 
-		var quaternion = new Quaternion();
+		var quaternion;
 
 		return function applyAxisAngle( axis, angle ) {
 
+			if ( quaternion === undefined ) quaternion = new Quaternion();
+
 			return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
 
 		};
@@ -313,10 +317,12 @@ Object.assign( Vector3.prototype, {
 
 	project: function () {
 
-		var matrix = new Matrix4();
+		var matrix;
 
 		return function project( camera ) {
 
+			if ( matrix === undefined ) matrix = new Matrix4();
+
 			matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
 			return this.applyMatrix4( matrix );
 
@@ -326,10 +332,12 @@ Object.assign( Vector3.prototype, {
 
 	unproject: function () {
 
-		var matrix = new Matrix4();
+		var matrix;
 
 		return function unproject( camera ) {
 
+			if ( matrix === undefined ) matrix = new Matrix4();
+
 			matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
 			return this.applyMatrix4( matrix );
 
@@ -403,11 +411,17 @@ Object.assign( Vector3.prototype, {
 
 	clampScalar: function () {
 
-		var min = new Vector3();
-		var max = new Vector3();
+		var min, max;
 
 		return function clampScalar( minVal, maxVal ) {
 
+			if ( min === undefined ) {
+
+				min = new Vector3();
+				max = new Vector3();
+
+			}
+
 			min.set( minVal, minVal, minVal );
 			max.set( maxVal, maxVal, maxVal );
 
@@ -571,10 +585,12 @@ Object.assign( Vector3.prototype, {
 
 	projectOnPlane: function () {
 
-		var v1 = new Vector3();
+		var v1;
 
 		return function projectOnPlane( planeNormal ) {
 
+			if ( v1 === undefined ) v1 = new Vector3();
+
 			v1.copy( this ).projectOnVector( planeNormal );
 
 			return this.sub( v1 );
@@ -588,10 +604,12 @@ Object.assign( Vector3.prototype, {
 		// reflect incident vector off plane orthogonal to normal
 		// normal is assumed to have unit length
 
-		var v1 = new Vector3();
+		var v1;
 
 		return function reflect( normal ) {
 
+			if ( v1 === undefined ) v1 = new Vector3();
+
 			return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
 
 		};