Browse Source

Merge pull request #5453 from arose/patch-1

Vector3: Added array and offset to toArray()
Mr.doob 10 years ago
parent
commit
832377e3ec
4 changed files with 37 additions and 8 deletions
  1. 10 2
      src/math/Quaternion.js
  2. 8 2
      src/math/Vector2.js
  3. 9 2
      src/math/Vector3.js
  4. 10 2
      src/math/Vector4.js

+ 10 - 2
src/math/Quaternion.js

@@ -483,9 +483,17 @@ THREE.Quaternion.prototype = {
 
 
 	},
 	},
 
 
-	toArray: function () {
+	toArray: function ( array, offset ) {
 
 
-		return [ this._x, this._y, this._z, this._w ];
+		if ( array === undefined ) array = [];
+		if ( offset === undefined ) offset = 0;
+
+		array[ offset ] = this._x;
+		array[ offset + 1 ] = this._y;
+		array[ offset + 2 ] = this._z;
+		array[ offset + 3 ] = this._w;
+
+		return array;
 
 
 	},
 	},
 
 

+ 8 - 2
src/math/Vector2.js

@@ -386,9 +386,15 @@ THREE.Vector2.prototype = {
 
 
 	},
 	},
 
 
-	toArray: function () {
+	toArray: function ( array, offset ) {
 
 
-		return [ this.x, this.y ];
+		if ( array === undefined ) array = [];
+		if ( offset === undefined ) offset = 0;
+
+		array[ offset ] = this.x;
+		array[ offset + 1 ] = this.y;
+
+		return array;
 
 
 	},
 	},
 
 

+ 9 - 2
src/math/Vector3.js

@@ -796,9 +796,16 @@ THREE.Vector3.prototype = {
 
 
 	},
 	},
 
 
-	toArray: function () {
+	toArray: function ( array, offset ) {
 
 
-		return [ this.x, this.y, this.z ];
+		if ( array === undefined ) array = [];
+		if ( offset === undefined ) offset = 0;
+
+		array[ offset ] = this.x;
+		array[ offset + 1 ] = this.y;
+		array[ offset + 2 ] = this.z;
+
+		return array;
 
 
 	},
 	},
 
 

+ 10 - 2
src/math/Vector4.js

@@ -634,9 +634,17 @@ THREE.Vector4.prototype = {
 
 
 	},
 	},
 
 
-	toArray: function () {
+	toArray: function ( array, offset ) {
 
 
-		return [ this.x, this.y, this.z, this.w ];
+		if ( array === undefined ) array = [];
+		if ( offset === undefined ) offset = 0;
+
+		array[ offset ] = this.x;
+		array[ offset + 1 ] = this.y;
+		array[ offset + 2 ] = this.z;
+		array[ offset + 3 ] = this.w;
+
+		return array;
 
 
 	},
 	},