Browse Source

Merge pull request #5735 from WestLangley/dev-attrib

Added fromAttribute() method to the Vector* classes
Mr.doob 10 years ago
parent
commit
189c984cd4
3 changed files with 42 additions and 0 deletions
  1. 13 0
      src/math/Vector2.js
  2. 14 0
      src/math/Vector3.js
  3. 15 0
      src/math/Vector4.js

+ 13 - 0
src/math/Vector2.js

@@ -398,6 +398,19 @@ THREE.Vector2.prototype = {
 
 	},
 
+	fromAttribute: function ( attribute, index, offset ) {
+
+	    if ( offset === undefined ) offset = 0;
+
+	    index = index * attribute.itemSize + offset;
+
+	    this.x = attribute.array[ index ];
+	    this.y = attribute.array[ index + 1 ];
+
+	    return this;
+
+	},
+
 	clone: function () {
 
 		return new THREE.Vector2( this.x, this.y );

+ 14 - 0
src/math/Vector3.js

@@ -809,6 +809,20 @@ THREE.Vector3.prototype = {
 
 	},
 
+	fromAttribute: function ( attribute, index, offset ) {
+
+	    if ( offset === undefined ) offset = 0;
+
+	    index = index * attribute.itemSize + offset;
+
+	    this.x = attribute.array[ index ];
+	    this.y = attribute.array[ index + 1 ];
+	    this.z = attribute.array[ index + 2 ];
+
+	    return this;
+
+	},
+
 	clone: function () {
 
 		return new THREE.Vector3( this.x, this.y, this.z );

+ 15 - 0
src/math/Vector4.js

@@ -648,6 +648,21 @@ THREE.Vector4.prototype = {
 
 	},
 
+	fromAttribute: function ( attribute, index, offset ) {
+
+	    if ( offset === undefined ) offset = 0;
+
+	    index = index * attribute.itemSize + offset;
+
+	    this.x = attribute.array[ index ];
+	    this.y = attribute.array[ index + 1 ];
+	    this.z = attribute.array[ index + 2 ];
+	    this.w = attribute.array[ index + 3 ];
+
+	    return this;
+
+	},
+
 	clone: function () {
 
 		return new THREE.Vector4( this.x, this.y, this.z, this.w );